From 6a633dee838417ed68cf91fbd2e9b3b9fa07bd8f Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Fri, 19 Sep 2008 05:31:14 +0000 Subject: Simplified ServiceDiscoverer. Started to use it to create factories to resolve ClassNotFoundExceptions. Renamed calculator-osgi to calculator-equinox and a few fixes to get it working in Eclipse. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@696924 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultModelFactoryExtensionPoint.java | 8 +- .../DefaultPackageProcessorExtensionPoint.java | 2 +- ...DefaultStAXArtifactProcessorExtensionPoint.java | 2 +- ...efaultStAXAttributeProcessorExtensionPoint.java | 2 +- .../DefaultURLArtifactProcessorExtensionPoint.java | 2 +- .../processor/DefaultUnknownElementProcessor.java | 272 ----------------- .../processor/ExtensibleStAXArtifactProcessor.java | 7 +- .../DefaultModelResolverExtensionPoint.java | 2 +- .../DefaultContributionScannerExtensionPoint.java | 2 +- .../DefaultContributionListenerExtensionPoint.java | 2 +- .../DefaultContextFactoryExtensionPoint.java | 6 +- ...faultEndpointResolverFactoryExtensionPoint.java | 2 +- .../DefaultProviderFactoryExtensionPoint.java | 2 +- ...efaultSCADefinitionsProviderExtensionPoint.java | 2 +- .../DefaultDataBindingExtensionPoint.java | 2 +- .../DefaultTransformerExtensionPoint.java | 2 +- .../equinox/EquinoxServiceDiscoverer.java | 23 +- .../equinox/EquinoxServiceDiscovererTestCase.java | 19 +- .../sca/core/DefaultExtensionPointRegistry.java | 8 +- .../core/DefaultModuleActivatorExtensionPoint.java | 2 +- .../sca/core/DefaultUtilityExtensionPoint.java | 8 +- .../ContextClassLoaderServiceDiscoverer.java | 43 +-- .../sca/extensibility/ServiceDeclaration.java | 2 + .../sca/extensibility/ServiceDiscoverer.java | 39 ++- .../sca/extensibility/ServiceDiscovery.java | 98 +----- ...ontextClassLoaderServiceDiscovererTestCase.java | 18 +- .../sca/extension/helper/impl/DiscoveryUtils.java | 2 +- .../tuscany/sca/host/embedded/SCADomain.java | 7 +- .../sca/host/embedded/impl/ReallySmallRuntime.java | 2 +- branches/sca-equinox/modules/host-jetty/pom.xml | 3 +- .../java/DefaultJavaInterfaceFactory.java | 2 +- .../apache/tuscany/sca/node/SCANodeFactory.java | 10 +- .../tuscany/sca/node/impl/RuntimeBootStrapper.java | 3 +- .../sca/node/equinox/launcher/EquinoxHost.java | 12 +- .../launcher/EquinoxLauncherBundleHelper.java | 4 +- .../node/equinox/launcher/NodeLauncherUtil.java | 28 ++ .../util/PolicyHandlerDefinitionsLoader.java | 2 +- .../sca-equinox/samples/calculator-equinox/README | 97 ++++++ .../samples/calculator-equinox/calculator.png | Bin 0 -> 20552 bytes .../samples/calculator-equinox/calculator.svg | 329 +++++++++++++++++++++ .../sca-equinox/samples/calculator-equinox/pom.xml | 91 ++++++ .../src/main/java/calculator/AddService.java | 28 ++ .../src/main/java/calculator/AddServiceImpl.java | 35 +++ .../src/main/java/calculator/CalculatorClient.java | 62 ++++ .../main/java/calculator/CalculatorService.java | 35 +++ .../java/calculator/CalculatorServiceImpl.java | 70 +++++ .../src/main/java/calculator/DivideService.java | 28 ++ .../main/java/calculator/DivideServiceImpl.java | 35 +++ .../src/main/java/calculator/MultiplyService.java | 28 ++ .../main/java/calculator/MultiplyServiceImpl.java | 35 +++ .../src/main/java/calculator/SubtractService.java | 28 ++ .../main/java/calculator/SubtractServiceImpl.java | 35 +++ .../src/main/resources/Calculator.composite | 54 ++++ .../test/java/calculator/CalculatorTestCase.java | 57 ++++ .../sca-equinox/samples/calculator-osgi/README | 97 ------ .../sca-equinox/samples/calculator-osgi/build.xml | 72 ----- .../samples/calculator-osgi/calculator.png | Bin 20552 -> 0 bytes .../samples/calculator-osgi/calculator.svg | 329 --------------------- .../sca-equinox/samples/calculator-osgi/pom.xml | 99 ------- .../src/main/java/calculator/AddService.java | 28 -- .../src/main/java/calculator/AddServiceImpl.java | 35 --- .../src/main/java/calculator/CalculatorClient.java | 62 ---- .../main/java/calculator/CalculatorService.java | 35 --- .../java/calculator/CalculatorServiceImpl.java | 70 ----- .../src/main/java/calculator/DivideService.java | 28 -- .../main/java/calculator/DivideServiceImpl.java | 35 --- .../src/main/java/calculator/MultiplyService.java | 28 -- .../main/java/calculator/MultiplyServiceImpl.java | 35 --- .../src/main/java/calculator/SubtractService.java | 28 -- .../main/java/calculator/SubtractServiceImpl.java | 35 --- .../src/main/resources/Calculator.composite | 54 ---- .../test/java/calculator/CalculatorTestCase.java | 57 ---- .../sca-equinox/samples/calculator-rcp/pom.xml | 78 ++++- .../src/main/java/calculator/rcp/Activator.java | 13 +- 74 files changed, 1324 insertions(+), 1593 deletions(-) delete mode 100644 branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/README create mode 100644 branches/sca-equinox/samples/calculator-equinox/calculator.png create mode 100644 branches/sca-equinox/samples/calculator-equinox/calculator.svg create mode 100644 branches/sca-equinox/samples/calculator-equinox/pom.xml create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddService.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddServiceImpl.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorService.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideService.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideServiceImpl.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractService.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/main/resources/Calculator.composite create mode 100644 branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/README delete mode 100644 branches/sca-equinox/samples/calculator-osgi/build.xml delete mode 100644 branches/sca-equinox/samples/calculator-osgi/calculator.png delete mode 100644 branches/sca-equinox/samples/calculator-osgi/calculator.svg delete mode 100644 branches/sca-equinox/samples/calculator-osgi/pom.xml delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddService.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddServiceImpl.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideService.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideServiceImpl.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyServiceImpl.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractService.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractServiceImpl.java delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/main/resources/Calculator.composite delete mode 100644 branches/sca-equinox/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java (limited to 'branches/sca-equinox') diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java index b69c58a0ff..bf8d75dba9 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.contribution; import java.lang.reflect.Constructor; import java.util.HashMap; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; @@ -91,8 +92,9 @@ public class DefaultModelFactoryExtensionPoint implements ModelFactoryExtensionP // Dynamically load a factory class declared under META-INF/services try { - Class factoryClass = ServiceDiscovery.getInstance().loadFirstServiceClass(factoryInterface); - if (factoryClass != null) { + ServiceDeclaration factoryDeclaration = ServiceDiscovery.getInstance().getFirstServiceDeclaration(factoryInterface.getName()); + if (factoryDeclaration != null) { + Class factoryClass = factoryDeclaration.loadClass(); try { // Default empty constructor @@ -115,7 +117,7 @@ public class DefaultModelFactoryExtensionPoint implements ModelFactoryExtensionP // Call the newInstance static method on the factory abstract class try { - factory = ServiceDiscovery.getInstance().newFactoryClassInstance(factoryInterface); + factory = ServiceDiscovery.getInstance().newFactoryClassInstance(factoryInterface.getName()); } catch (Exception e) { throw new IllegalArgumentException(e); } diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java index 426d7beb29..589bcc9d92 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java @@ -67,7 +67,7 @@ public class DefaultPackageProcessorExtensionPoint implements PackageProcessorEx // Get the processor service declarations Set processorDeclarations; try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(PackageProcessor.class); + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(PackageProcessor.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java index f23ebc2c36..46ac9897a1 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java @@ -161,7 +161,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends // Get the processor service declarations Set processorDeclarations; try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class); + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class.getName()); } catch (IOException e) { IllegalStateException ie = new IllegalStateException(e); error("IllegalStateException", extensibleStAXProcessor, ie); diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java index d81e236b40..aa8875c08f 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java @@ -155,7 +155,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends // Get the processor service declarations Set processorDeclarations; try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXAttributeProcessor.class); + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXAttributeProcessor.class.getName()); } catch (IOException e) { IllegalStateException ie = new IllegalStateException(e); error("IllegalStateException", extensibleStAXAttributeProcessor, ie); diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java index 045c201638..4d7374d803 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java @@ -127,7 +127,7 @@ public class DefaultURLArtifactProcessorExtensionPoint // Get the processor service declarations Set processorDeclarations; try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class); + processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class.getName()); } catch (IOException e) { IllegalStateException ie = new IllegalStateException(e); error("IllegalStateException", staxProcessor, ie); diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java deleted file mode 100644 index d52a110c05..0000000000 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java +++ /dev/null @@ -1,272 +0,0 @@ -package org.apache.tuscany.sca.contribution.processor; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; - -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.traversal.DocumentTraversal; -import org.w3c.dom.traversal.NodeFilter; -import org.w3c.dom.traversal.NodeIterator; -import org.w3c.dom.traversal.TreeWalker; - -public class DefaultUnknownElementProcessor{ - - private Monitor monitor; - private static final Logger logger = Logger.getLogger(DefaultUnknownElementProcessor.class.getName()); - - public DefaultUnknownElementProcessor(Monitor monitor){ - this.monitor = monitor; - } - private DocumentBuilderFactory documentBuilderFactory; - private Document document; - - /** - * Reads the contetns of the unknown elements and generates the DOM - * @param reader - * @param name - * @return - * @throws XMLStreamException - */ - public Object read(XMLStreamReader reader, QName name) throws XMLStreamException{ - - int event = reader.getEventType(); - int level = 0; - ArrayList elementList = new ArrayList(); - document = createDocument(); - while(reader.hasNext()){ - switch(event){ - case START_ELEMENT: - elementList.add(reader.getName().getLocalPart()); - if(level == 0){ - generateDOM(reader,null); - level++; - } - else{ - generateDOM(reader,elementList.get(elementList.size()-2).toString()); - } - - break; - case END_ELEMENT: - elementList.remove(reader.getName().getLocalPart()); - } - if(reader.hasNext()){ - event = reader.next(); - } - - if(event == START_ELEMENT || event == END_ELEMENT){ - if(reader.getName().equals(name)){ - break; - } - } - } - return document; - } - - /** - * Writes unknown portions back to the writer - * @param model - * @param writer - */ - public void write(Object model, XMLStreamWriter writer) { - - if( ! (model instanceof Document)) { - return; - } - - Document doc = (Document)model; - try{ - DocumentTraversal traversal = (DocumentTraversal)doc; - TreeWalker walker = traversal.createTreeWalker(doc.getDocumentElement(),NodeFilter.SHOW_ALL, null, true); - writeDOM(walker,writer); - } - catch(Exception e){ - if (logger.isLoggable(Level.SEVERE)) { - logger.log(Level.SEVERE, "Document not created "); - } - error("Document not created",document,e); - } - } - - /** - * Method to generate the DOM - * @param reader - * @param parent - * @throws Exception - */ - //private void generateDOM(String elementText, String parent) { - private void generateDOM(XMLStreamReader reader, String parent) { - try{ - String elePrefix = reader.getPrefix(); - String eleQName = reader.getLocalName(); - if (elePrefix != null && elePrefix.length() != 0) { - eleQName = elePrefix + ":" + eleQName; - } - - Element element = document.createElementNS(reader.getNamespaceURI(), eleQName); - - int attributeCount = reader.getAttributeCount(); - for(int i = 0;i < attributeCount;i++){ - String ns = reader.getAttributeNamespace(i); - String prefix = reader.getAttributePrefix(i); - String qname = reader.getAttributeLocalName(i); - String value = reader.getAttributeValue(i); - if (prefix != null && prefix.length() != 0) { - qname = prefix + ":" + qname; - } - element.setAttributeNS(ns,qname,value); - } - if(parent == null){ - if(document != null){ - document.appendChild(element); - } - else{ - if (logger.isLoggable(Level.SEVERE)) { - logger.log(Level.SEVERE, "Document not created "); - } - error("Document not created",document,element); - } - } - else{ - Node parentNode = getParentNode(document,parent); - if(parentNode != null){ - parentNode.appendChild(element); - } - else{ - if (logger.isLoggable(Level.SEVERE)) { - logger.log(Level.SEVERE, "Parent node not found"); - } - error("Parent node not found",document,parentNode.getNodeName()); - } - } - } - catch(Exception e){ - e.printStackTrace(); - if (logger.isLoggable(Level.SEVERE)) { - logger.log(Level.SEVERE, "Document not created "); - } - error("Document not created",document,e); - } - } - - /** - * Method to create an empty document - * @return - */ - private Document createDocument() { - try { - if (documentBuilderFactory == null) { - documentBuilderFactory = DocumentBuilderFactory.newInstance(); - } - document = documentBuilderFactory.newDocumentBuilder().newDocument(); - return document; - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } - return null; - } - - /** - * Method to traverse the DOM structure and write the elements - * @param walker - * @param writer - * @throws XMLStreamException - */ - private void writeDOM(TreeWalker walker,XMLStreamWriter writer) throws XMLStreamException { - - Node parent = walker.getCurrentNode(); - - writer.writeStartElement(parent.getPrefix(), parent.getLocalName(), parent.getNamespaceURI()); - - NamedNodeMap attributes = parent.getAttributes(); - - for(int i = 0;i processor = (StAXArtifactProcessor)processors.getProcessor(name); if (processor == null) { - DefaultUnknownElementProcessor unknownElementProcessor = new DefaultUnknownElementProcessor(monitor); Location location = source.getLocation(); if (logger.isLoggable(Level.WARNING)) { logger.warning("Element " + name + " cannot be processed. (" + location + ")"); } warning("ElementCannotBeProcessed", processors, name, location); - //return null; - return unknownElementProcessor.read(source,name); + return null; } return processor.read(source); } @@ -155,8 +152,6 @@ public class ExtensibleStAXArtifactProcessor if (processor != null) { processor.write(model, outputSource); } else { - DefaultUnknownElementProcessor unknownElementProcessor = new DefaultUnknownElementProcessor(monitor); - unknownElementProcessor.write(model,outputSource); if (logger.isLoggable(Level.WARNING)) { logger.warning("No StAX processor is configured to handle " + model.getClass()); } diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java index 77570aa13d..878a2efdab 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java @@ -97,7 +97,7 @@ public class DefaultModelResolverExtensionPoint implements ModelResolverExtensio // Get the model resolver service declarations Set modelResolverDeclarations; try { - modelResolverDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModelResolver.class); + modelResolverDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModelResolver.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java index 24aae45b59..7610cb5aba 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java @@ -64,7 +64,7 @@ public class DefaultContributionScannerExtensionPoint implements ContributionSca // Get the scanner service declarations Set scannerDeclarations; try { - scannerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionScanner.class); + scannerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionScanner.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java index 1ab80e344b..f36595d64f 100644 --- a/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java +++ b/branches/sca-equinox/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java @@ -82,7 +82,7 @@ public class DefaultContributionListenerExtensionPoint implements ContributionLi // Get the listener service declarations Set listenerDeclarations; try { - listenerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionListener.class); + listenerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionListener.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java index 5a0aefe55d..7a35036f03 100644 --- a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java +++ b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java @@ -23,6 +23,7 @@ import java.lang.reflect.Constructor; import java.util.HashMap; import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; /** @@ -93,8 +94,9 @@ public class DefaultContextFactoryExtensionPoint implements ContextFactoryExtens // Dynamically load a factory class declared under META-INF/services try { - Class factoryClass = ServiceDiscovery.getInstance().loadFirstServiceClass(factoryInterface); - if (factoryClass != null) { + ServiceDeclaration factoryDeclaration = ServiceDiscovery.getInstance().getFirstServiceDeclaration(factoryInterface.getName()); + if (factoryDeclaration != null) { + Class factoryClass = factoryDeclaration.loadClass(); // Default empty constructor Constructor constructor = factoryClass.getConstructor(ExtensionPointRegistry.class); diff --git a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java index 2849c27c1a..81f619cef3 100644 --- a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java +++ b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java @@ -100,7 +100,7 @@ public class DefaultEndpointResolverFactoryExtensionPoint implements EndpointRes Set factoryDeclarations; ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance(); try { - factoryDeclarations = serviceDiscovery.getServiceDeclarations(EndpointResolverFactory.class); + factoryDeclarations = serviceDiscovery.getServiceDeclarations(EndpointResolverFactory.class.getName()); } catch (Exception e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java index dfc3ddb468..0b7b779b46 100644 --- a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java +++ b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java @@ -129,7 +129,7 @@ public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExte Set factoryDeclarations; ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance(); try { - factoryDeclarations = serviceDiscovery.getServiceDeclarations(factoryClass); + factoryDeclarations = serviceDiscovery.getServiceDeclarations(factoryClass.getName()); } catch (Exception e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java index 068d0d12d7..3e1f1a10c5 100644 --- a/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java +++ b/branches/sca-equinox/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java @@ -68,7 +68,7 @@ public class DefaultSCADefinitionsProviderExtensionPoint implements try { defnProviderDecls = - ServiceDiscovery.getInstance().getServiceDeclarations(SCADefinitionsProvider.class); + ServiceDiscovery.getInstance().getServiceDeclarations(SCADefinitionsProvider.class.getName()); for (ServiceDeclaration aDefnProviderDecl : defnProviderDecls) { providerClass = aDefnProviderDecl.loadClass(); diff --git a/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java index b2da024a72..51cbba02d2 100644 --- a/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java +++ b/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java @@ -111,7 +111,7 @@ public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoi // Get the databinding service declarations Set dataBindingDeclarations; try { - dataBindingDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(DataBinding.class); + dataBindingDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(DataBinding.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java b/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java index 7aa55d2cff..3bd729b472 100644 --- a/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java +++ b/branches/sca-equinox/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java @@ -115,7 +115,7 @@ public class DefaultTransformerExtensionPoint implements TransformerExtensionPoi Set transformerDeclarations; try { - transformerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(transformerClass); + transformerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(transformerClass.getName()); } catch (IOException e) { throw new IllegalStateException(e); diff --git a/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java b/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java index 5ab5a66077..c918ad735d 100644 --- a/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java +++ b/branches/sca-equinox/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java @@ -23,6 +23,8 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; import java.security.AccessController; import java.security.PrivilegedAction; @@ -181,8 +183,17 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { } return attributes; } + + public ServiceDeclaration getFirstServiceDeclaration(String name) throws IOException { + Set declarations = getServiceDeclarations(name); + if (declarations.isEmpty()) { + return null; + } else { + return declarations.iterator().next(); + } + } - public Set discover(String serviceName, boolean firstOnly) { + public Set getServiceDeclarations(String serviceName) throws IOException { boolean debug = logger.isLoggable(Level.FINE); Set descriptors = new HashSet(); @@ -256,9 +267,6 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(bundle, url, className, attributes); descriptors.add(descriptor); - if (firstOnly) { - return descriptors; - } } } } finally { @@ -278,4 +286,11 @@ public class EquinoxServiceDiscoverer implements ServiceDiscoverer { return descriptors; } + public Object newFactoryClassInstance(String name) throws SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException { + Class factoryClass = Class.forName(name, false, getClass().getClassLoader()); + Method newInstanceMethod = factoryClass.getMethod("newInstance"); + Object factory = newInstanceMethod.invoke(null); + return factory; + } + } diff --git a/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java b/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java index 3126365748..c21e4984f5 100644 --- a/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java +++ b/branches/sca-equinox/modules/extensibility-equinox/src/test/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscovererTestCase.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.extensibility.equinox; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.util.ArrayList; @@ -131,21 +132,19 @@ public class EquinoxServiceDiscovererTestCase { } @Test - public void testDiscovery() { - Set descriptors = - discoverer.discover("test.TestService", false); + public void testDiscovery() throws IOException { + Set descriptors = discoverer.getServiceDeclarations("test.TestService"); Assert.assertEquals(1, descriptors.size()); - descriptors = discoverer.discover("notthere", false); + descriptors = discoverer.getServiceDeclarations("notthere"); Assert.assertEquals(0, descriptors.size()); } @Test - public void testDiscoveryFirst() { - Set descriptors = - discoverer.discover("test.TestService", true); - Assert.assertEquals(1, descriptors.size()); - descriptors = discoverer.discover("notthere", true); - Assert.assertEquals(0, descriptors.size()); + public void testDiscoveryFirst() throws IOException { + ServiceDeclaration descriptor = discoverer.getFirstServiceDeclaration("test.TestService"); + Assert.assertNotNull(descriptor); + descriptor = discoverer.getFirstServiceDeclaration("notthere"); + Assert.assertNull(descriptor); } diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java index 48f240559c..12979723b1 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; /** @@ -103,9 +104,10 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { // Dynamically load an extension point class declared under META-INF/services try { - Class extensionPointClass = - ServiceDiscovery.getInstance().loadFirstServiceClass(extensionPointType); - if (extensionPointClass != null) { + ServiceDeclaration extensionPointDeclaration = ServiceDiscovery.getInstance().getFirstServiceDeclaration(extensionPointType.getName()); + if (extensionPointDeclaration != null) { + Class extensionPointClass = extensionPointDeclaration.loadClass(); + // Construct the extension point Constructor[] constructors = extensionPointClass.getConstructors(); Constructor constructor = getConstructor(constructors, new Class[] {ExtensionPointRegistry.class}); diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java index 8ca030c0dd..d84f28f11e 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java @@ -65,7 +65,7 @@ public class DefaultModuleActivatorExtensionPoint implements ModuleActivatorExte // Get the activator service declarations Set activatorDeclarations; try { - activatorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class); + activatorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java index 6f7c83c8d9..9906bef909 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; /** @@ -103,9 +104,10 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint { // Dynamically load a utility class declared under META-INF/utilities try { - Class utilityClass = - ServiceDiscovery.getInstance().loadFirstServiceClass(utilityType); - if (utilityClass != null) { + ServiceDeclaration utilityDeclaration =ServiceDiscovery.getInstance().getFirstServiceDeclaration(utilityType.getName()); + if (utilityDeclaration != null) { + Class utilityClass = utilityDeclaration.loadClass(); + // Construct the utility Constructor[] constructors = utilityClass.getConstructors(); Constructor constructor = getConstructor(constructors, new Class[] {ExtensionPointRegistry.class}); diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java index 2e11234095..0f408600aa 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java @@ -24,13 +24,14 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; import java.net.URLConnection; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -85,7 +86,7 @@ public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer { } public Class loadClass(String className) throws ClassNotFoundException { - return classLoaderReference.get().loadClass(className); + return Class.forName(className, false, classLoaderReference.get()); } public String toString() { @@ -112,21 +113,12 @@ public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer { this.classLoaderReference = new WeakReference(classLoader); } - private List getResources(final String name, final boolean firstOnly) throws IOException { + private List getResources(final String name) throws IOException { try { return AccessController.doPrivileged(new PrivilegedExceptionAction>() { public List run() throws IOException { - if (firstOnly) { - URL url = classLoaderReference.get().getResource(name); - if (url != null) { - return Arrays.asList(url); - } else { - return Collections.emptyList(); - } - } else { - List urls = Collections.list(classLoaderReference.get().getResources(name)); - return urls; - } + List urls = Collections.list(classLoaderReference.get().getResources(name)); + return urls; } }); } catch (PrivilegedActionException e) { @@ -169,13 +161,22 @@ public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer { return attributes; } - public Set discover(String serviceName, boolean firstOnly) { + public ServiceDeclaration getFirstServiceDeclaration(String name) throws IOException { + Set declarations = getServiceDeclarations(name); + if (declarations.isEmpty()) { + return null; + } else { + return declarations.iterator().next(); + } + } + + public Set getServiceDeclarations(String serviceName) { Set descriptors = new HashSet(); String name = "META-INF/services/" + serviceName; boolean debug = logger.isLoggable(Level.FINE); try { - for (final URL url : getResources(name, firstOnly)) { + for (final URL url : getResources(name)) { if (debug) { logger.fine("Reading service provider file: " + url.toExternalForm()); } @@ -223,9 +224,6 @@ public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer { } ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(url, className, attributes); descriptors.add(descriptor); - if (firstOnly) { - return descriptors; - } } } } finally { @@ -245,4 +243,11 @@ public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer { } + public Object newFactoryClassInstance(String name) throws SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException { + Class factoryClass = Class.forName(name, false, classLoaderReference.get()); + Method newInstanceMethod = factoryClass.getMethod("newInstance"); + Object factory = newInstanceMethod.invoke(null); + return factory; + } + } diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java index 403b6aa7a7..d7ac8b449f 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java @@ -37,11 +37,13 @@ public interface ServiceDeclaration { * @throws ClassNotFoundException */ Class loadClass(String className) throws ClassNotFoundException; + /** * Get the java class for the service impl * @return The java class */ Class loadClass() throws ClassNotFoundException; + /** * Get all attributes (name=value pairs) defined for the given entry * @return All attributes keyed by name diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java index 1722cd5f49..679e3d1f57 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java @@ -19,19 +19,44 @@ package org.apache.tuscany.sca.extensibility; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; import java.util.Set; /** * A SPI that allows different implementations of discovering service declarations */ public interface ServiceDiscoverer { + /** - * Discover the service descriptors by name - * @param serviceName The name of the service - * @param firstOnly A flag to indicate if only the first instance is to be discovered - * - * @return A set of service descriptors + * Get all service declarations for this interface + * + * @param name + * @return set of service declarations + * @throws IOException */ - Set discover(String serviceName, boolean firstOnly); - + public Set getServiceDeclarations(String name) throws IOException; + + /** + * Get first service declaration class for the given interface + * + * @param name + * @return service implementation class + * @throws IOException + * @throws ClassNotFoundException + */ + public ServiceDeclaration getFirstServiceDeclaration(String name) throws IOException; + + /** + * Create a new instance of a factory service class. + * + * @param name + * @return service implementation class + * @throws SecurityException + * @throws NoSuchMethodException + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + public Object newFactoryClassInstance(String name) throws SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException; + } diff --git a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java index ce41a44068..552691ab6b 100644 --- a/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java +++ b/branches/sca-equinox/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java @@ -21,12 +21,9 @@ package org.apache.tuscany.sca.extensibility; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.HashSet; import java.util.Set; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -37,13 +34,12 @@ import java.util.logging.Logger; * * @version $Rev$ $Date$ */ -public class ServiceDiscovery { +public class ServiceDiscovery implements ServiceDiscoverer { private static final Logger logger = Logger.getLogger(ServiceDiscovery.class.getName()); private final static ServiceDiscovery INSTANCE = new ServiceDiscovery(); private ServiceDiscoverer discoverer; - private Set registeredClassLoaders = new HashSet(); /** * Get an instance of Service discovery, one instance is created per @@ -69,101 +65,27 @@ public class ServiceDiscovery { discoverer = sd; } - /** - * @deprecated - * Register a ClassLoader with this discovery mechanism. Tuscany extension - * ClassLoaders are registered here. - * - * @param classLoader - */ - @Deprecated - public synchronized void registerClassLoader(ClassLoader classLoader) { - registeredClassLoaders.add(classLoader); - } - - /** - * @deprecated - * Unregister a ClassLoader with this discovery mechanism. - * - * @param classLoader - */ - @Deprecated - public synchronized void unregisterClassLoader(ClassLoader classLoader) { - registeredClassLoaders.remove(classLoader); - } - - /** - * Get all service declarations for this name - * - * @param name - * @return set of service declarations - * @throws IOException - */ public Set getServiceDeclarations(String name) throws IOException { - Set services = getServiceDiscoverer().discover(name, false); + Set services = getServiceDiscoverer().getServiceDeclarations(name); return services; } - /** - * Get all service declarations for this interface - * - * @param serviceInterface - * @return set of service declarations - * @throws IOException - */ - public Set getServiceDeclarations(Class serviceInterface) throws IOException { - - return getServiceDeclarations(serviceInterface.getName()); - } - - /** - * Load one service implementation class for this interface - * - * @param serviceInterface - * @return service implementation class - * @throws IOException - * @throws ClassNotFoundException - */ - public Class loadFirstServiceClass(final Class serviceInterface) throws IOException, ClassNotFoundException { + public ServiceDeclaration getFirstServiceDeclaration(final String name) throws IOException { // Try System property first String className = AccessController.doPrivileged(new PrivilegedAction() { public String run() { - return System.getProperty(serviceInterface.getName()); + return System.getProperty(name); } }); - if (className != null) { - try { - // Try the classloader for the service interface first - return Class.forName(className, false, serviceInterface.getClassLoader()); - } catch (ClassNotFoundException e) { - try { - // Try the thread context classloader - return Class.forName(className, false, Thread.currentThread().getContextClassLoader()); - } catch (ClassNotFoundException ex) { - logger.log(Level.WARNING, ex.getMessage(), ex); - } - } - } - Set services = getServiceDiscoverer().discover(serviceInterface.getName(), true); - if (services.isEmpty()) { - return null; + if (className == null) { + className = name; } - return services.iterator().next().loadClass(); + ServiceDeclaration service = getServiceDiscoverer().getFirstServiceDeclaration(className); + return service; } - /** - * Create a new instance of a factory service class. - * - * @param serviceInterface - * @return service implementation class - * @throws SecurityException - * @throws NoSuchMethodException - * @throws InvocationTargetException - * @throws IllegalAccessException - */ - public Object newFactoryClassInstance(final Class serviceInterface) throws SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { - Method newInstanceMethod = serviceInterface.getMethod("newInstance"); - Object factory = newInstanceMethod.invoke(null); + public Object newFactoryClassInstance(String name) throws SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException { + Object factory = getServiceDiscoverer().newFactoryClassInstance(name); return factory; } diff --git a/branches/sca-equinox/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java b/branches/sca-equinox/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java index fd508402fc..4c965420ca 100644 --- a/branches/sca-equinox/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java +++ b/branches/sca-equinox/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.extensibility; +import java.io.IOException; import java.util.Set; import junit.framework.Assert; @@ -44,21 +45,20 @@ public class ContextClassLoaderServiceDiscovererTestCase { @Test public void testDiscovery() { Set discriptors = - discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", false); + discover.getServiceDeclarations("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint"); Assert.assertEquals(1, discriptors.size()); discriptors = - discover.discover("notthere", false); + discover.getServiceDeclarations("notthere"); Assert.assertEquals(0, discriptors.size()); } @Test - public void testDiscoveryFirst() { - Set discriptors = - discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", true); - Assert.assertEquals(1, discriptors.size()); - discriptors = - discover.discover("notthere", true); - Assert.assertEquals(0, discriptors.size()); + public void testDiscoveryFirst() throws IOException { + ServiceDeclaration descriptor = + discover.getFirstServiceDeclaration("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint"); + Assert.assertNotNull(descriptor); + descriptor = discover.getFirstServiceDeclaration("notthere"); + Assert.assertNull(descriptor); } diff --git a/branches/sca-equinox/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/DiscoveryUtils.java b/branches/sca-equinox/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/DiscoveryUtils.java index 720d409a44..5a7ac48e62 100644 --- a/branches/sca-equinox/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/DiscoveryUtils.java +++ b/branches/sca-equinox/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/DiscoveryUtils.java @@ -43,7 +43,7 @@ public class DiscoveryUtils { List activators; try { Set activatorClasses = - ServiceDiscovery.getInstance().getServiceDeclarations(activatorClass); + ServiceDiscovery.getInstance().getServiceDeclarations(activatorClass.getName()); activators = new ArrayList(); for (ServiceDeclaration declaration : activatorClasses) { try { diff --git a/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java b/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java index a7f148cdda..aaa4c6ee95 100644 --- a/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java +++ b/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.host.embedded; import java.lang.reflect.Constructor; +import org.apache.tuscany.sca.extensibility.ServiceDeclaration; import org.apache.tuscany.sca.extensibility.ServiceDiscovery; import org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain; import org.apache.tuscany.sca.host.embedded.management.ComponentManager; @@ -174,9 +175,9 @@ public abstract class SCADomain { final ClassLoader runtimeClassLoader = SCADomain.class.getClassLoader(); final ClassLoader applicationClassLoader = Thread.currentThread().getContextClassLoader(); - Class implClass = ServiceDiscovery.getInstance().loadFirstServiceClass(SCADomain.class); + ServiceDeclaration implDeclaration = ServiceDiscovery.getInstance().getFirstServiceDeclaration(SCADomain.class.getName()); - if (implClass == null) { + if (implDeclaration == null) { // Create a default SCA domain implementation domain = @@ -187,6 +188,7 @@ public abstract class SCADomain { // Create an instance of the discovered SCA domain implementation Constructor constructor = null; try { + Class implClass = implDeclaration.loadClass(); constructor = implClass.getConstructor(ClassLoader.class, ClassLoader.class, @@ -204,6 +206,7 @@ public abstract class SCADomain { composites); } else { + Class implClass = implDeclaration.loadClass(); constructor = implClass.getConstructor(ClassLoader.class, String.class); domain = (SCADomain)constructor.newInstance(runtimeClassLoader, domainURI); } diff --git a/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java b/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java index 55b6afb6f2..be700cb2d0 100644 --- a/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java +++ b/branches/sca-equinox/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java @@ -305,7 +305,7 @@ public class ReallySmallRuntime { modules = new ArrayList(); try { Set moduleActivators = - ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class); + ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class.getName()); Set moduleClasses = new HashSet(); for (ServiceDeclaration moduleDeclarator : moduleActivators) { if (moduleClasses.contains(moduleDeclarator.getClassName())) { diff --git a/branches/sca-equinox/modules/host-jetty/pom.xml b/branches/sca-equinox/modules/host-jetty/pom.xml index 9d4570b9ec..736a6f8dde 100644 --- a/branches/sca-equinox/modules/host-jetty/pom.xml +++ b/branches/sca-equinox/modules/host-jetty/pom.xml @@ -75,7 +75,8 @@ org.mortbay.jetty.servlet;version="6.1.7", org.mortbay.log;version="6.1.7", org.mortbay.resource;version="6.1.7", - org.mortbay.thread;version="6.1.7" + org.mortbay.thread;version="6.1.7", + * diff --git a/branches/sca-equinox/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java b/branches/sca-equinox/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java index 7853b597d3..2a0fc8099a 100644 --- a/branches/sca-equinox/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java +++ b/branches/sca-equinox/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java @@ -70,7 +70,7 @@ public class DefaultJavaInterfaceFactory extends JavaInterfaceFactoryImpl implem // Get the databinding service declarations Set visitorDeclarations; try { - visitorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(JavaInterfaceVisitor.class); + visitorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(JavaInterfaceVisitor.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java b/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java index e41afd29c4..2c91032653 100644 --- a/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java +++ b/branches/sca-equinox/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java @@ -123,13 +123,11 @@ public abstract class SCANodeFactory { // 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"); + Class discoveryClass = Class.forName("org.apache.tuscany.sca.extensibility.ServiceDiscovery"); Object instance = discoveryClass.getMethod("getInstance").invoke(null); - Class factoryImplClass = - (Class)discoveryClass.getMethod("loadFirstServiceClass", Class.class) - .invoke(instance, SCANodeFactory.class); - if (factoryImplClass != null) { + Object factoryDeclaration = discoveryClass.getMethod("getFirstServiceDeclaration", String.class).invoke(instance, SCANodeFactory.class.getName()); + if (factoryDeclaration != null) { + Class factoryImplClass = (Class)factoryDeclaration.getClass().getMethod("loadClass").invoke(factoryDeclaration); scaNodeFactory = (SCANodeFactory)factoryImplClass.newInstance(); return scaNodeFactory; } diff --git a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java index 5b0e31fd03..15a348afd8 100644 --- a/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java +++ b/branches/sca-equinox/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java @@ -299,6 +299,7 @@ public class RuntimeBootStrapper { //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); } @@ -310,7 +311,7 @@ public class RuntimeBootStrapper { modules = new ArrayList(); try { Set moduleActivators = - ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class); + ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class.getName()); Set moduleClasses = new HashSet(); for (ServiceDeclaration moduleDeclarator : moduleActivators) { if (moduleClasses.contains(moduleDeclarator.getClassName())) { diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java index 6efdcb0da5..aabfd4bcfe 100644 --- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java +++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxHost.java @@ -20,6 +20,7 @@ package org.apache.tuscany.sca.node.equinox.launcher; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.bundleLocation; +import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.installBundle; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.string; import static org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME; @@ -153,7 +154,7 @@ public class EquinoxHost { // Install the launcher bundle String bundleLocation = bundleLocation(); logger.info("Installing launcher bundle: " + bundleLocation); - launcherBundle = bundleContext.installBundle(bundleLocation); + launcherBundle = installBundle(bundleContext, bundleLocation); logger.info("Starting bundle: " + string(launcherBundle, false)); launcherBundle.start(); @@ -229,6 +230,15 @@ public class EquinoxHost { if (mf.isFile()) { Manifest manifest = new Manifest(new FileInputStream(mf)); bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + } else { + if (file.getPath().endsWith("target/classes")) { + // Development mode, MANIFEST.MF is outside the bundle location + mf = new File(file.getParentFile().getParentFile(), "META-INF/MANIFEST.MF"); + if (mf.isFile()) { + Manifest manifest = new Manifest(new FileInputStream(mf)); + bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + } + } } } else { JarFile jar = new JarFile(file, false); diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java index 3f88bd89e9..b2c80f6fd7 100644 --- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java +++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxLauncherBundleHelper.java @@ -3,6 +3,7 @@ package org.apache.tuscany.sca.node.equinox.launcher; import static java.lang.System.currentTimeMillis; import static java.lang.System.getProperty; import static java.lang.System.setProperty; +import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.installBundle; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.libraryBundle; import static org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil.string; @@ -77,9 +78,10 @@ public class EquinoxLauncherBundleHelper implements BundleListener { continue; } long installStart = currentTimeMillis(); - Bundle bundle = bundleContext.installBundle(bundleFile); + Bundle bundle = installBundle(bundleContext, bundleFile); logger.info("Bundle installed in " + (currentTimeMillis() - installStart) + " ms: " + string(bundle, false)); installedBundles.add(bundle); + alreadyInstalledBundleNames.add(bundleName); } } diff --git a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java index bf65c3f323..0bbf09d101 100644 --- a/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java +++ b/branches/sca-equinox/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java @@ -31,8 +31,10 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.lang.reflect.Constructor; import java.net.URI; import java.net.URISyntaxException; @@ -50,6 +52,7 @@ import java.util.zip.ZipInputStream; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; /** * Common functions and constants used by the admin components. @@ -344,6 +347,31 @@ final class NodeLauncherUtil { return path; } } + + static Bundle installBundle(BundleContext bundleContext, String location) throws BundleException, IOException { + // Development mode, copy the MANIFEST.MF file to the bundle location + if (location.endsWith("/target/classes/")) { + File target = file(new URL(location)); + File targetManifest = new File(target, "META-INF/MANIFEST.MF"); + File sourceManifest = new File(target.getParentFile().getParentFile(), "META-INF/MANIFEST.MF"); + targetManifest.getParentFile().mkdirs(); + OutputStream os = new FileOutputStream(targetManifest); + InputStream is = new FileInputStream(sourceManifest); + byte[] buf = new byte[2048]; + for (;;) { + int l = is.read(buf); + if (l == -1) { + break; + } + os.write(buf, 0, l); + } + is.close(); + os.close(); + } + + Bundle bundle = bundleContext.installBundle(location); + return bundle; + } static String string(Bundle b, boolean verbose) { StringBuffer sb = new StringBuffer(); diff --git a/branches/sca-equinox/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java b/branches/sca-equinox/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java index 3a37ed3c41..e9af4912a3 100644 --- a/branches/sca-equinox/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java +++ b/branches/sca-equinox/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java @@ -42,7 +42,7 @@ public class PolicyHandlerDefinitionsLoader { // Get the processor service declarations Set sds; try { - sds = ServiceDiscovery.getInstance().getServiceDeclarations(PolicyHandler.class); + sds = ServiceDiscovery.getInstance().getServiceDeclarations(PolicyHandler.class.getName()); } catch (IOException e) { throw new IllegalStateException(e); } diff --git a/branches/sca-equinox/samples/calculator-equinox/README b/branches/sca-equinox/samples/calculator-equinox/README new file mode 100644 index 0000000000..cde5fe981f --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/README @@ -0,0 +1,97 @@ +Calculator Sample +================= +This sample implements a simple calculator using SCA components. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens open a command prompt, navigate +to this sample directory and do: + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator.jar calculator.CalculatorClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - the first component, calls +-/* as + appropriate + CalculatorServiceImpl.java + AddService.java - adds two numbers + AddServiceImpl.java + SubtractService.java - subtracts one number from another + SubtractServiceImpl.java + MultiplyService.java - multiplies two numbers + MultiplyServiceImpl.java + DivideService.java - divides one number by another + DivideServiceImpl.java + CalculatorClient.java - starts the SCA Runtime and + deploys the Calculator.composite. + It then calls the deployed Calculator + Components services + resources/ + Calculator.composite - the SCA assembly for this sample + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + calculator.png - a pictorial representation of the sample + .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd calculator +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] 3 + 2=5.0 + [java] 3 - 2=1.0 + [java] 3 * 2=6.0 + [java] 3 / 2=1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/branches/sca-equinox/samples/calculator-equinox/calculator.png b/branches/sca-equinox/samples/calculator-equinox/calculator.png new file mode 100644 index 0000000000..995a57b1fd Binary files /dev/null and b/branches/sca-equinox/samples/calculator-equinox/calculator.png differ diff --git a/branches/sca-equinox/samples/calculator-equinox/calculator.svg b/branches/sca-equinox/samples/calculator-equinox/calculator.svg new file mode 100644 index 0000000000..af34f07e04 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/calculator.svg @@ -0,0 +1,329 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + diff --git a/branches/sca-equinox/samples/calculator-equinox/pom.xml b/branches/sca-equinox/samples/calculator-equinox/pom.xml new file mode 100644 index 0000000000..394fc331ab --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/pom.xml @@ -0,0 +1,91 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.4-SNAPSHOT + ../../pom.xml + + sample-calculator-equinox + Apache Tuscany SCA Calculator OSGi Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-node-api + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-node-launcher-equinox + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-node-impl + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-node-runtime + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-extensibility-equinox + 1.4-SNAPSHOT + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddService.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..188451ebac --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The Add service interface + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddServiceImpl.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..7ca8fb04b5 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Adding " + n1 + " and " + n2); + return n1 + n2; + } + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..c193b2ce66 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package calculator; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + */ +@Scope("COMPOSITE") @EagerInit +public class CalculatorClient { + + private CalculatorService calculatorService; + + @Reference + public void setCalculatorService(CalculatorService calculatorService) { + this.calculatorService = calculatorService; + } + + @Init + public void calculate() { + + // Calculate + System.out.println("SCA API ClassLoader: " + print(Reference.class.getClassLoader())); + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + } + + private static String print(ClassLoader cl) { + StringBuffer buf = new StringBuffer(); + for (; cl != null;) { + buf.append(cl.toString()); + buf.append(' '); + cl = cl.getParent(); + } + return buf.toString(); + } + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorService.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..3d861f2018 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.Reference; + + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideService.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..30d248208b --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The divide service interface + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideServiceImpl.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..1323edf55a --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Dividing " + n1 + " with " + n2); + return n1 / n2; + } + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyServiceImpl.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..91b803bc9e --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Multiplying " + n1 + " with " + n2); + return n1 * n2; + } + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractService.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..bf0d1882b6 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractServiceImpl.java b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..58cc4a3547 --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + Logger logger = Logger.getLogger("calculator"); + logger.log(Level.FINEST, "Subtracting " + n1 + " from " + n2); + return n1 - n2; + } + +} diff --git a/branches/sca-equinox/samples/calculator-equinox/src/main/resources/Calculator.composite b/branches/sca-equinox/samples/calculator-equinox/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..913081b9be --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/main/resources/Calculator.composite @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java b/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.java new file mode 100644 index 0000000000..dc0da7d20d --- /dev/null +++ b/branches/sca-equinox/samples/calculator-equinox/src/test/java/calculator/CalculatorTestCase.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 calculator; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Scope; + +/** + * This shows how to test the Calculator composition. + */ +@Scope("COMPOSITE") +@EagerInit +public class CalculatorTestCase extends TestCase { + + private NodeLauncher launcher; + private SCANode node; + + @Override + protected void setUp() throws Exception { + launcher = NodeLauncher.newInstance(); + node = launcher.createNodeFromClassLoader("Calculator.composite", getClass().getClassLoader()); + System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader()); + node.start(); + } + + @Override + protected void tearDown() throws Exception { + if (launcher != null) { + node.stop(); + launcher.destroy(); + } + } + + public void testDummy() { + } + +} diff --git a/branches/sca-equinox/samples/calculator-osgi/README b/branches/sca-equinox/samples/calculator-osgi/README deleted file mode 100644 index cde5fe981f..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/README +++ /dev/null @@ -1,97 +0,0 @@ -Calculator Sample -================= -This sample implements a simple calculator using SCA components. - -The README in the samples directory (the directory above this) provides -general instructions about building and running samples. Take a look there -first. - -If you just want to run it to see what happens open a command prompt, navigate -to this sample directory and do: - -ant run - -OR if you don't have ant, on Windows do - -java -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-calculator.jar calculator.CalculatorClient - -and on *nix do - -java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-calculator.jar calculator.CalculatorClient - -Sample Overview ---------------- -The sample provides a single calculator service with a default SCA (java) -binding. The CalculatorClient exercises this interface by calling add, -subtract, multiply and divide operations. This results in messages passing to -the appropriate components in the composite across the local wires. - -calculator/ - src/ - main/ - java/ - calculator/ - CalculatorService.java - the first component, calls +-/* as - appropriate - CalculatorServiceImpl.java - AddService.java - adds two numbers - AddServiceImpl.java - SubtractService.java - subtracts one number from another - SubtractServiceImpl.java - MultiplyService.java - multiplies two numbers - MultiplyServiceImpl.java - DivideService.java - divides one number by another - DivideServiceImpl.java - CalculatorClient.java - starts the SCA Runtime and - deploys the Calculator.composite. - It then calls the deployed Calculator - Components services - resources/ - Calculator.composite - the SCA assembly for this sample - test/ - java/ - calculator/ - CalculatorTestCase.java - JUnit test case - calculator.png - a pictorial representation of the sample - .composite file - build.xml - the Ant build file - pom.xml - the Maven build file - -Building And Running The Sample Using Ant ------------------------------------------ -With the binary distribution the sample can be built and run using Ant as -follows - -cd calculator -ant compile -ant run - -You should see the following output from the run target. - -run: - [java] 3 + 2=5.0 - [java] 3 - 2=1.0 - [java] 3 * 2=6.0 - [java] 3 / 2=1.5 - -Building And Running The Sample Using Maven -------------------------------------------- -With either the binary or source distributions the sample can be built and run -using Maven as follows. - -cd calculator -mvn - -You should see the following output from the test phase. - -------------------------------------------------------- - T E S T S -------------------------------------------------------- -Running calculator.CalculatorTestCase -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.272 sec - -Results : - -Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 - -This shows that the Junit test cases have run successfully. diff --git a/branches/sca-equinox/samples/calculator-osgi/build.xml b/branches/sca-equinox/samples/calculator-osgi/build.xml deleted file mode 100644 index c4b755ef94..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/build.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/branches/sca-equinox/samples/calculator-osgi/calculator.png b/branches/sca-equinox/samples/calculator-osgi/calculator.png deleted file mode 100644 index 995a57b1fd..0000000000 Binary files a/branches/sca-equinox/samples/calculator-osgi/calculator.png and /dev/null differ diff --git a/branches/sca-equinox/samples/calculator-osgi/calculator.svg b/branches/sca-equinox/samples/calculator-osgi/calculator.svg deleted file mode 100644 index af34f07e04..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/calculator.svg +++ /dev/null @@ -1,329 +0,0 @@ - - - - - - - - - - image/svg+xml - - - - - - - - Calculator - - CalculatorServiceComponent - - - CalculatorService - AddServiceComponent - - SubtractServiceComponent - - MultiplyServiceComponent - - DivideServiceComponent - addService - subtractService - multiplyService - divideService - - - - - - diff --git a/branches/sca-equinox/samples/calculator-osgi/pom.xml b/branches/sca-equinox/samples/calculator-osgi/pom.xml deleted file mode 100644 index a1d371df73..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/pom.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-sca - 1.4-SNAPSHOT - ../../pom.xml - - sample-calculator-osgi - Apache Tuscany SCA Calculator OSGi Sample - - - - apache.incubator - http://people.apache.org/repo/m2-incubating-repository - - - - - - org.apache.tuscany.sca - tuscany-node-api - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-node-impl - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-implementation-java-runtime - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-implementation-node-runtime - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-extensibility-equinox - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-node-launcher-equinox - 1.4-SNAPSHOT - compile - - - - javax.servlet - servlet-api - 2.5 - provided - - - - junit - junit - 4.2 - test - - - - - - ${artifactId} - - diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddService.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddService.java deleted file mode 100644 index 188451ebac..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddService.java +++ /dev/null @@ -1,28 +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 calculator; - -/** - * The Add service interface - */ -public interface AddService { - - double add(double n1, double n2); - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddServiceImpl.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddServiceImpl.java deleted file mode 100644 index 7ca8fb04b5..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/AddServiceImpl.java +++ /dev/null @@ -1,35 +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 calculator; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the Add service - */ -public class AddServiceImpl implements AddService { - - public double add(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.FINEST, "Adding " + n1 + " and " + n2); - return n1 + n2; - } - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java deleted file mode 100644 index c193b2ce66..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorClient.java +++ /dev/null @@ -1,62 +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 calculator; - -import org.osoa.sca.annotations.EagerInit; -import org.osoa.sca.annotations.Init; -import org.osoa.sca.annotations.Reference; -import org.osoa.sca.annotations.Scope; - -/** - * This client program shows how to create an SCA runtime, start it, - * and locate and invoke a SCA component - */ -@Scope("COMPOSITE") @EagerInit -public class CalculatorClient { - - private CalculatorService calculatorService; - - @Reference - public void setCalculatorService(CalculatorService calculatorService) { - this.calculatorService = calculatorService; - } - - @Init - public void calculate() { - - // Calculate - System.out.println("SCA API ClassLoader: " + print(Reference.class.getClassLoader())); - System.out.println("3 + 2=" + calculatorService.add(3, 2)); - System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); - System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); - System.out.println("3 / 2=" + calculatorService.divide(3, 2)); - } - - private static String print(ClassLoader cl) { - StringBuffer buf = new StringBuffer(); - for (; cl != null;) { - buf.append(cl.toString()); - buf.append(' '); - cl = cl.getParent(); - } - return buf.toString(); - } - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java deleted file mode 100644 index 031fa8b912..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorService.java +++ /dev/null @@ -1,35 +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 calculator; - - -/** - * The Calculator service interface. - */ -public interface CalculatorService { - - double add(double n1, double n2); - - double subtract(double n1, double n2); - - double multiply(double n1, double n2); - - double divide(double n1, double n2); - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java deleted file mode 100644 index 3d861f2018..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/CalculatorServiceImpl.java +++ /dev/null @@ -1,70 +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 calculator; - -import org.osoa.sca.annotations.Reference; - - -/** - * An implementation of the Calculator service. - */ -public class CalculatorServiceImpl implements CalculatorService { - - private AddService addService; - private SubtractService subtractService; - private MultiplyService multiplyService; - private DivideService divideService; - - @Reference - public void setAddService(AddService addService) { - this.addService = addService; - } - - @Reference - public void setSubtractService(SubtractService subtractService) { - this.subtractService = subtractService; - } - - @Reference - public void setDivideService(DivideService divideService) { - this.divideService = divideService; - } - - @Reference - public void setMultiplyService(MultiplyService multiplyService) { - this.multiplyService = multiplyService; - } - - public double add(double n1, double n2) { - return addService.add(n1, n2); - } - - public double subtract(double n1, double n2) { - return subtractService.subtract(n1, n2); - } - - public double multiply(double n1, double n2) { - return multiplyService.multiply(n1, n2); - } - - public double divide(double n1, double n2) { - return divideService.divide(n1, n2); - } - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideService.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideService.java deleted file mode 100644 index 30d248208b..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideService.java +++ /dev/null @@ -1,28 +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 calculator; - -/** - * The divide service interface - */ -public interface DivideService { - - double divide(double n1, double n2); - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideServiceImpl.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideServiceImpl.java deleted file mode 100644 index 1323edf55a..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/DivideServiceImpl.java +++ /dev/null @@ -1,35 +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 calculator; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the Divide service. - */ -public class DivideServiceImpl implements DivideService { - - public double divide(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.FINEST, "Dividing " + n1 + " with " + n2); - return n1 / n2; - } - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java deleted file mode 100644 index 5290605938..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyService.java +++ /dev/null @@ -1,28 +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 calculator; - -/** - * The interface for the multiply service - */ -public interface MultiplyService { - - double multiply(double n1, double n2); - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyServiceImpl.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyServiceImpl.java deleted file mode 100644 index 91b803bc9e..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/MultiplyServiceImpl.java +++ /dev/null @@ -1,35 +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 calculator; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the Multiply service. - */ -public class MultiplyServiceImpl implements MultiplyService { - - public double multiply(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.FINEST, "Multiplying " + n1 + " with " + n2); - return n1 * n2; - } - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractService.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractService.java deleted file mode 100644 index bf0d1882b6..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractService.java +++ /dev/null @@ -1,28 +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 calculator; - -/** - * The interface for the multiply service - */ -public interface SubtractService { - - double subtract(double n1, double n2); - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractServiceImpl.java b/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractServiceImpl.java deleted file mode 100644 index 58cc4a3547..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/java/calculator/SubtractServiceImpl.java +++ /dev/null @@ -1,35 +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 calculator; - -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * An implementation of the subtract service. - */ -public class SubtractServiceImpl implements SubtractService { - - public double subtract(double n1, double n2) { - Logger logger = Logger.getLogger("calculator"); - logger.log(Level.FINEST, "Subtracting " + n1 + " from " + n2); - return n1 - n2; - } - -} diff --git a/branches/sca-equinox/samples/calculator-osgi/src/main/resources/Calculator.composite b/branches/sca-equinox/samples/calculator-osgi/src/main/resources/Calculator.composite deleted file mode 100644 index 913081b9be..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/main/resources/Calculator.composite +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/branches/sca-equinox/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java b/branches/sca-equinox/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java deleted file mode 100644 index dc0da7d20d..0000000000 --- a/branches/sca-equinox/samples/calculator-osgi/src/test/java/calculator/CalculatorTestCase.java +++ /dev/null @@ -1,57 +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 calculator; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.node.SCANode; -import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; -import org.osoa.sca.annotations.EagerInit; -import org.osoa.sca.annotations.Scope; - -/** - * This shows how to test the Calculator composition. - */ -@Scope("COMPOSITE") -@EagerInit -public class CalculatorTestCase extends TestCase { - - private NodeLauncher launcher; - private SCANode node; - - @Override - protected void setUp() throws Exception { - launcher = NodeLauncher.newInstance(); - node = launcher.createNodeFromClassLoader("Calculator.composite", getClass().getClassLoader()); - System.out.println("SCA Node API ClassLoader: " + node.getClass().getClassLoader()); - node.start(); - } - - @Override - protected void tearDown() throws Exception { - if (launcher != null) { - node.stop(); - launcher.destroy(); - } - } - - public void testDummy() { - } - -} diff --git a/branches/sca-equinox/samples/calculator-rcp/pom.xml b/branches/sca-equinox/samples/calculator-rcp/pom.xml index a487076de6..c50048c028 100644 --- a/branches/sca-equinox/samples/calculator-rcp/pom.xml +++ b/branches/sca-equinox/samples/calculator-rcp/pom.xml @@ -25,7 +25,7 @@ 1.4-SNAPSHOT ../../pom.xml - sample.calculator.rcp + sample-calculator-rcp Apache Tuscany SCA Calculator RCP Sample @@ -34,6 +34,7 @@ + org.apache.tuscany.sca @@ -70,13 +71,79 @@ 1.4-SNAPSHOT compile - + + + org.eclipse.swt.win32.win32 + x86 + 3.3.0-v3346 + + + + org.eclipse + jface + 3.3.0-I20070606-0010 + + + org.eclipse + swt + + + org.eclipse.core + commands + + + org.eclipse.equinox + common + + + + + + org.eclipse.core + commands + 3.3.0-I20070605-0010 + + javax.servlet servlet-api @@ -90,6 +157,7 @@ test + ${artifactId} @@ -108,8 +176,6 @@ org.eclipse.jdt.launching.JRE_CONTAINER - org.eclipse.pde.core.requiredPlugins - @@ -123,4 +189,4 @@ - \ No newline at end of file + diff --git a/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java b/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java index 50f68dcb01..2b1bae34de 100644 --- a/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java +++ b/branches/sca-equinox/samples/calculator-rcp/src/main/java/calculator/rcp/Activator.java @@ -21,9 +21,9 @@ package calculator.rcp; import java.io.File; import org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoverer; -import org.apache.tuscany.sca.node.SCAContribution; import org.apache.tuscany.sca.node.SCANode; -import org.apache.tuscany.sca.node.SCANodeFactory; +import org.apache.tuscany.sca.node.equinox.launcher.Contribution; +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -39,6 +39,7 @@ public class Activator extends AbstractUIPlugin { // The shared instance private static Activator plugin; + private NodeLauncher launcher; private SCANode node; /** @@ -54,9 +55,8 @@ public class Activator extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); plugin = this; - Class cls = EquinoxServiceDiscoverer.class; - SCANodeFactory factory = SCANodeFactory.newInstance(); - node = factory.createSCANode("Calculator.composite", new SCAContribution("c1", new File("target/classes").toURI().toString())); + launcher = NodeLauncher.newInstance(); + node = launcher.createNode("Calculator.composite", new Contribution("c1", new File("target/classes").toURI().toString())); node.start(); } @@ -70,6 +70,9 @@ public class Activator extends AbstractUIPlugin { if (node != null) { node.stop(); } + if (launcher != null) { + launcher.destroy(); + } } /** -- cgit v1.2.3