From 5559ef5edbf8d3616f7a4b497b2a459b0ee4082b Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:07:07 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835122 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/binding/sca/DistributedSCABinding.java | 37 ++++ .../sca/impl/DistributedSCABindingImpl.java | 111 ++++++++++ .../sca/impl/RuntimeSCABindingProvider.java | 61 ++++++ .../sca/impl/RuntimeSCABindingProviderFactory.java | 71 +++++++ .../impl/RuntimeSCAReferenceBindingProvider.java | 232 +++++++++++++++++++++ .../sca/impl/RuntimeSCAServiceBindingProvider.java | 138 ++++++++++++ .../binding/sca/impl/SCABindingFactoryImpl.java | 36 ++++ .../sca/binding/sca/impl/SCABindingImpl.java | 194 +++++++++++++++++ ...g.apache.tuscany.sca.assembly.SCABindingFactory | 18 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 ++ 10 files changed, 917 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory create mode 100644 sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory (limited to 'sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main') diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java new file mode 100644 index 0000000000..be89a30193 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.sca; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.SCABinding; + + +/** + * Represents an SCA binding used in the distributed runtime. + * At the moment just provides us with a sensibly named type + * against which the distributed sca binding providers can be registered + * + * @version $Rev: 556322 $ $Date: 2007-07-14 19:53:15 +0100 (Sat, 14 Jul 2007) $ + */ +public interface DistributedSCABinding extends Binding { + + public SCABinding getSCABinding(); + public void setSCABinging(SCABinding scaBinding); + +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java new file mode 100644 index 0000000000..e12fd82f97 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.sca.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; + +/** + * The Distributed SCA binding wrapper for the SCA binding model object. This is currently + * just used to locate the remote binding extension and pass the SCA binding to the remote + * extension. It isn't used in the model itself + * + * @version $Rev: 564307 $ $Date: 2007-08-09 18:48:29 +0100 (Thu, 09 Aug 2007) $ + */ +public class DistributedSCABindingImpl implements DistributedSCABinding { + + private SCABinding scaBinding; + + /** + * Getter for the wrapped sca binding model object + * + * @return the sca binding model element + */ + public SCABinding getSCABinding(){ + return scaBinding; + } + + /** + * Setter for the wrapped sca binding model element + * + * @param the sca binding model element + */ + public void setSCABinging(SCABinding scaBinding){ + this.scaBinding = scaBinding; + } + + + // Operation implementations provided to make this class a + // valid Binding + + /** + * Returns the binding URI. + * + * @return the binding uri + */ + public String getURI(){ + return null; + } + + /** + * Sets the binding URI. + * + * @param uri the binding uri + */ + public void setURI(String uri){ + } + + /** + * Returns the binding name. + * + * @return the binding name + */ + public String getName(){ + return null; + } + + /** + * Sets the binding name. + * + * @param name the binding name + */ + public void setName(String name){ + } + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + public boolean isUnresolved(){ + return false; + } + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + public void setUnresolved(boolean unresolved){ + } + + +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java new file mode 100644 index 0000000000..5c1cefb808 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * The local SCA Binding provider implementation. It is not currently used. + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + + public RuntimeSCABindingProvider(RuntimeComponent component, RuntimeComponentReference reference, SCABinding binding) { + this.reference = reference; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public Invoker createInvoker(Operation operation) { + return null; + } + + public void start() { + } + + public void stop() { + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java new file mode 100644 index 0000000000..1ea8354695 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The factory for creating SCA Binding providers + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProviderFactory implements BindingProviderFactory { + + private ExtensionPointRegistry extensionPoints; + private SCANode node = null; + + public RuntimeSCABindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + ModelFactoryExtensionPoint factories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + NodeFactory domainFactory = factories.getFactory(NodeFactory.class); + + if (domainFactory != null) { + node = domainFactory.getNode(); + } + + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + + return new RuntimeSCAReferenceBindingProvider(extensionPoints, node, component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + return new RuntimeSCAServiceBindingProvider(extensionPoints, node, component, service, binding); + } + + public Class getModelType() { + return SCABinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java new file mode 100644 index 0000000000..d86cdd4c7c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java @@ -0,0 +1,232 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.domain.SCADomainService; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceUnavailableException; + +/** + * The sca reference binding provider mediates between the twin requirements of + * local sca bindings and remote sca bindings. In the local case is does + * very little. When the sca binding model is set as being remote (because a + * reference target can't be resolved in the current model) this binding will + * try and create a remote connection to it + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvider { + + private SCANode node; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private SCABinding binding; + private boolean started = false; + + private BindingProviderFactory distributedProviderFactory = null; + private ReferenceBindingProvider distributedProvider = null; + + public RuntimeSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints, + SCANode domain, + RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + this.node = domain; + this.component = component; + this.reference = reference; + this.binding = binding; + + // look to see if a distributed SCA binding implementation has + // been included on the classpath. This will be needed by the + // provider itself to do it's thing + ProviderFactoryExtensionPoint factoryExtensionPoint = + extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + distributedProviderFactory = + (BindingProviderFactory)factoryExtensionPoint + .getProviderFactory(DistributedSCABinding.class); + + + // determine if the target is remote. If we can tell now then this will + // do some initialization before we get to run time + isTargetRemote(); + } + + public boolean isTargetRemote() { + boolean targetIsRemote = false; + + // first look at the target service and see if this has been resolved + if (((OptimizableBinding)binding).getTargetComponentService() != null) { + if (((OptimizableBinding)binding).getTargetComponentService().isUnresolved() == true) { + targetIsRemote = true; + } else { + targetIsRemote = false; + } + } else { + // if no target is found then this could be a completely dynamic + // reference, e.g. a callback, so check the domain to see if the service is available + // at this node. The binding uri might be null here if the dynamic reference has been + // fully configured yet. It won't have all of the information until invocation time + if ((node != null) && (binding.getURI() != null)) { + SCADomainService serviceDiscovery = node.getDomainService(); + + String serviceUrl = + serviceDiscovery.findServiceEndpoint(node.getDomainURI(), + binding.getURI(), + SCABinding.class.getName()); + if ((serviceUrl == null) || serviceUrl.equals("")) { + targetIsRemote = false; + } else { + targetIsRemote = true; + } + + } + } + + // if we think the target is remote check that everything is configured correctly + if (targetIsRemote) { + // initialize the remote provider if it hasn't been done already + if (distributedProvider == null) { + if (!reference.getInterfaceContract().getInterface().isRemotable()) { + throw new IllegalStateException("Reference interface not remoteable for component: " + component + .getName() + + " and reference: " + + reference.getName()); + } + + if (distributedProviderFactory == null) { + throw new IllegalStateException("No distributed SCA binding available for component: " + component + .getName() + + " and reference: " + + reference.getName()); + } + + if (node == null) { + throw new IllegalStateException("No distributed domain available for component: " + component + .getName() + + " and reference: " + + reference.getName()); + } + + // create the remote provider + DistributedSCABinding distributedBinding = new DistributedSCABindingImpl(); + distributedBinding.setSCABinging(binding); + + distributedProvider = distributedProviderFactory + .createReferenceBindingProvider(component, reference, distributedBinding); + } + } + + return targetIsRemote; + } + + public InterfaceContract getBindingInterfaceContract() { + if (isTargetRemote()) { + return distributedProvider.getBindingInterfaceContract(); + } else { + return reference.getInterfaceContract(); + } + } + + public boolean supportsOneWayInvocation() { + if (isTargetRemote()) { + return distributedProvider.supportsOneWayInvocation(); + } else { + return false; + } + } + + /** + * @param wire + */ + private Invoker getInvoker(RuntimeWire wire, Operation operation) { + EndpointReference target = wire.getTarget(); + if (target != null) { + RuntimeComponentService service = (RuntimeComponentService)target.getContract(); + if (service != null) { // not a callback wire + SCABinding scaBinding = service.getBinding(SCABinding.class); + return service.getInvoker(scaBinding, wire.getSource().getInterfaceContract(), operation); + } + } + return null; + } + + public Invoker createInvoker(Operation operation) { + if (isTargetRemote()) { + return distributedProvider.createInvoker(operation); + } else { + RuntimeWire wire = reference.getRuntimeWire(binding); + Invoker invoker = getInvoker(wire, operation); + if (invoker == null) { + throw new ServiceUnavailableException("No service invoker is available for reference " + reference + .getName() + + " (bindingURI=" + + binding.getURI() + + " operation=" + + operation.getName() + + ")."); + } + return invoker; + } + } + + public void start() { + if (started) { + return; + } else { + started = true; + } + + // ComponentService service = ((WireableBinding)binding).getTargetComponentService(); + // if (service != null) { + // RuntimeWire wire = reference.getRuntimeWire(binding); + // InterfaceContract interfaceContract = service.getInterfaceContract(); + // boolean dynamicService = interfaceContract.getInterface().isDynamic(); + // if (!dynamicService) { + // wire.getTarget().setInterfaceContract(interfaceContract); + // } + // } + + if (distributedProvider != null) { + distributedProvider.start(); + } + } + + public void stop() { + if (distributedProvider != null) { + distributedProvider.stop(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java new file mode 100644 index 0000000000..8c74147de4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The sca service binding provider mediates between the twin requirements of + * local sca bindings and remote sca bindings. In the local case is does + * very little. When the sca binding model is set as being remote this binding will + * try and create a remote service endpoint for remote references to connect to + * + * @version $Rev$ $Date$ + */ +public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider { + + private SCANode node; + private RuntimeComponentService service; + private BindingProviderFactory distributedProviderFactory; + private ServiceBindingProvider distributedProvider; + private DistributedSCABinding distributedBinding; + + public RuntimeSCAServiceBindingProvider(ExtensionPointRegistry extensionPoints, + SCANode node, + RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + this.node = node; + this.service = service; + // if there is potentially a wire to this service that crosses the node boundary + if (service.getInterfaceContract().getInterface().isRemotable()) { + + // look to see if a distributed SCA binding implementation has + // been included on the classpath. This will be needed by the + // provider itself to do it's thing + ProviderFactoryExtensionPoint factoryExtensionPoint = + extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); + distributedProviderFactory = + (BindingProviderFactory)factoryExtensionPoint + .getProviderFactory(DistributedSCABinding.class); + + // Check the things that will generally be required to set up a + // distributed sca domain reference provider. I.e. make sure that we have a + // - distributed implementation of the sca binding available + // - distributed domain in which to look for remote endpoints + // - remotable interface on the service + if (distributedProviderFactory != null) { + if (this.node != null) { + if (!service.getInterfaceContract().getInterface().isRemotable()) { + throw new IllegalStateException("Reference interface not remoteable for component: "+ + component.getName() + + " and service: " + + service.getName()); + } + + // create a nested provider to handle the remote case + distributedBinding = new DistributedSCABindingImpl(); + distributedBinding.setSCABinging(binding); + + distributedProvider = + distributedProviderFactory.createServiceBindingProvider(component, service, distributedBinding); + + + } else { + /* do nothing at the moment as only apps using the node implementation + * will currently have the distributed domain set. + * + throw new IllegalStateException("No distributed domain available for component: "+ + component.getName() + + " and service: " + + service.getName()); + */ + } + } else { + /* do nothing at the moment as all services with remotable interfaces + * are marked as remote + throw new IllegalStateException("No distributed SCA binding available for component: "+ + component.getName() + + " and service: " + + service.getName()); + */ + } + } + } + + public InterfaceContract getBindingInterfaceContract() { + if (distributedProvider != null){ + return distributedProvider.getBindingInterfaceContract(); + } else { + return service.getInterfaceContract(); + } + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + if (distributedProvider != null) { + distributedProvider.start(); + } + } + + public void stop() { + if (distributedProvider != null) { + distributedProvider.stop(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java new file mode 100644 index 0000000000..666c264e2e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.sca.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; + +/** + * A factory for the SCA binding model. + * + * @version $Rev$ $Date$ + */ +public class SCABindingFactoryImpl implements SCABindingFactory { + + public SCABinding createSCABinding() { + return new SCABindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java new file mode 100644 index 0000000000..8c5ec98dbf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.sca.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * he assemly mode object for an SCA binding. + * + * @version $Rev$ $Date$ + */ +public class SCABindingImpl implements SCABinding, Extensible, PolicySetAttachPoint, OptimizableBinding { + private String name; + private String uri; + private List extensions = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + + private Component targetComponent; + private ComponentService targetComponentService; + private Binding targetBinding; + + /** + * Constructs a new SCA binding. + */ + protected SCABindingImpl() { + } + + // SCA Binding operations + + /** + * Setters for the binding name. Defaults to the + * name of the service or reference with which the binding is + * associated + * + * @return the biniding name + */ + public String getName() { + return name; + } + + /** + * Setter for the binding name + * + * @param name the binding name + */ + public void setName(String name) { + this.name = name; + } + + /** + * Getters for the binding URI. The computed URI for the + * service that the reference is targetting or which the service represents + * depending on whether the biding is associated with a reference or + * service + * + * @return the binding uri + */ + public String getURI() { + return uri; + } + + /** + * Setter for the binding uri + * + * @para uri the binding uri + */ + public void setURI(String uri) { + this.uri = uri; + } + + /** + * Returns a list of extension objects contained in this model object. + * + * @return a list of extension objects container in this model object + */ + public List getExtensions() { + return extensions; + } + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + public boolean isUnresolved() { + return false; + } + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + public void setUnresolved(boolean unresolved) { + } + + /** + * @see java.lang.Object#clone() + */ + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + // Wireable binding operations + + /** + * @return the targetComponent + */ + public Component getTargetComponent() { + return targetComponent; + } + + /** + * @param targetComponent the targetComponent to set + */ + public void setTargetComponent(Component targetComponent) { + this.targetComponent = targetComponent; + } + + /** + * @return the targetComponentService + */ + public ComponentService getTargetComponentService() { + return targetComponentService; + } + + /** + * @param targetComponentService the targetComponentService to set + */ + public void setTargetComponentService(ComponentService targetComponentService) { + this.targetComponentService = targetComponentService; + } + + /** + * @return the targetBinding + */ + public Binding getTargetBinding() { + return targetBinding; + } + + /** + * @param targetBinding the targetBinding to set + */ + public void setTargetBinding(Binding targetBinding) { + this.targetBinding = targetBinding; + } +} diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory new file mode 100644 index 0000000000..4efa03a933 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl diff --git a/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..5c6b8e21fc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-1.0/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.sca.impl.RuntimeSCABindingProviderFactory;model=org.apache.tuscany.sca.assembly.SCABinding -- cgit v1.2.3