From 7bf07e507a391b09ecc6f0dbdcd179cd728c39e5 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 9 Feb 2010 22:14:02 +0000 Subject: Rename ExtensibleDomainRegistry to ExtensibleDomainRegistryFactory git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@908255 13f79535-47bb-0310-9956-ffa450edef68 --- .../modules/sca-client-impl/META-INF/MANIFEST.MF | 1 + .../sca/client/impl/SCAClientFactoryImpl.java | 43 ++++++++++++++-------- 2 files changed, 28 insertions(+), 16 deletions(-) (limited to 'sca-java-2.x/trunk/modules/sca-client-impl') diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF index ae6fcb3ce3..d63aa101f1 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/sca-client-impl/META-INF/MANIFEST.MF @@ -8,6 +8,7 @@ Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt Bundle-Description: Apache Tuscany SCA Client Impl Import-Package: org.apache.tuscany.sca.assembly;version="2.0.0", org.apache.tuscany.sca.core;version="2.0.0", + org.apache.tuscany.sca.context;version="2.0.0", org.apache.tuscany.sca.node;version="2.0.0", org.apache.tuscany.sca.node.impl;version="2.0.0", org.apache.tuscany.sca.runtime;version="2.0.0", diff --git a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java index 1d6937364c..94c71cb48f 100644 --- a/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java +++ b/sca-java-2.x/trunk/modules/sca-client-impl/src/main/java/org/apache/tuscany/sca/client/impl/SCAClientFactoryImpl.java @@ -19,12 +19,12 @@ package org.apache.tuscany.sca.client.impl; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Proxy; import java.net.URI; import java.util.List; +import java.util.UUID; import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.context.CompositeContext; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; @@ -32,9 +32,13 @@ import org.apache.tuscany.sca.node.impl.NodeFactoryImpl; import org.apache.tuscany.sca.node.impl.NodeImpl; import org.apache.tuscany.sca.runtime.DomainRegistryFactory; import org.apache.tuscany.sca.runtime.EndpointRegistry; -import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistry; +import org.apache.tuscany.sca.runtime.ExtensibleDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; import org.oasisopen.sca.NoSuchDomainException; import org.oasisopen.sca.NoSuchServiceException; +import org.oasisopen.sca.ServiceReference; +import org.oasisopen.sca.ServiceRuntimeException; import org.oasisopen.sca.client.SCAClientFactory; import org.oasisopen.sca.client.SCAClientFactoryFinder; @@ -47,13 +51,14 @@ public class SCAClientFactoryImpl extends SCAClientFactory { private ExtensionPointRegistry extensionsRegistry; private EndpointRegistry endpointRegistry; private NodeFactoryImpl nodeFactory; + private CompositeContext compositeContext; public SCAClientFactoryImpl(URI domainURI) throws NoSuchDomainException { super(domainURI); this.nodeFactory = (NodeFactoryImpl)NodeFactory.getInstance(); this.extensionsRegistry = nodeFactory.getExtensionPoints(); - DomainRegistryFactory domainRegistryFactory = new ExtensibleDomainRegistry(extensionsRegistry); + DomainRegistryFactory domainRegistryFactory = ExtensibleDomainRegistryFactory.getInstance(extensionsRegistry); this.endpointRegistry = domainRegistryFactory.getEndpointRegistry(null, getDomainURI().toString()); // TODO: shouldnt use null for reg uri // TODO: if there is not an existing endpoint registry for the domain URI the // this should create an endpoint registry client for the remote domain (eg hazelcast native client) @@ -61,6 +66,9 @@ public class SCAClientFactoryImpl extends SCAClientFactory { if (endpointRegistry == null) { throw new NoSuchDomainException(domainURI.toString()); } + String client = "sca.client." + UUID.randomUUID(); + this.compositeContext = + new CompositeContext(extensionsRegistry, endpointRegistry, null, domainURI.toString(), client); } @Override @@ -76,27 +84,30 @@ public class SCAClientFactoryImpl extends SCAClientFactory { if (localNode != null) { return localNode.getService(serviceInterface, serviceName); } - - InvocationHandler handler = new SCAClientProxyHandler(serviceName, extensionsRegistry, endpointRegistry); - return (T)Proxy.newProxyInstance(serviceInterface.getClassLoader(), new Class[] {serviceInterface}, handler); + + RuntimeComponent component; + try { + component = (RuntimeComponent) endpoint.getComponent().clone(); + } catch (CloneNotSupportedException e) { + throw new ServiceRuntimeException(e); + } + compositeContext.bindComponent(component); + RuntimeEndpoint runtimeEndpoint = (RuntimeEndpoint) component.getServices().get(0).getEndpoints().get(0); + runtimeEndpoint.setRemote(true); + ServiceReference serviceReference = component.getComponentContext().getServiceReference(serviceInterface, runtimeEndpoint); + return serviceReference.getService(); + } private Node findLocalNode(Endpoint endpoint) { for (Node node : nodeFactory.getNodes().values()) { - for (Endpoint ep : ((NodeImpl)node).getServiceEndpoints()) { + for (Endpoint ep : ((NodeImpl)node).getServiceEndpoints()) { if (endpoint.getURI().equals(ep.getURI())) { return node; } - } + } } return null; } - private String getDomainName() { - // TODO: parse to extract just the domain name from the uri - if (getDomainURI().getHost() != null) { - return getDomainURI().getHost(); - } - return getDomainURI().toString(); - } } -- cgit v1.2.3