Change the creation of DistributedSCABinding to the factory to avoid OSGi violations

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776005 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
rfeng 2009-05-18 16:46:33 +00:00
parent 4b61a4eee8
commit 1f8bafbfc5
9 changed files with 139 additions and 106 deletions

View file

@ -6,25 +6,26 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apache.tuscany.sca.assembly.xml.osoa;
import org.apache.tuscany.sca.assembly.DistributedSCABinding;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
/**
* A factory for the SCA binding model.
*
*
* @version $Rev$ $Date$
*/
public class TestSCABindingFactoryImpl implements SCABindingFactory {
@ -32,4 +33,8 @@ public class TestSCABindingFactoryImpl implements SCABindingFactory {
return new TestSCABindingImpl();
}
public DistributedSCABinding createDistributedSCABinding() {
return null;
}
}

View file

@ -6,25 +6,26 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apache.tuscany.sca.assembly.xml;
import org.apache.tuscany.sca.assembly.DistributedSCABinding;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
/**
* A factory for the SCA binding model.
*
*
* @version $Rev$ $Date$
*/
public class TestSCABindingFactoryImpl implements SCABindingFactory {
@ -32,4 +33,8 @@ public class TestSCABindingFactoryImpl implements SCABindingFactory {
return new TestSCABindingImpl();
}
public DistributedSCABinding createDistributedSCABinding() {
return null;
}
}

View file

@ -6,31 +6,33 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apache.tuscany.sca.assembly;
/**
* A factory for the SCA binding model
*
*
* @version $Rev$ $Date$
*/
public interface SCABindingFactory {
/**
* Create a new SCA binding.
*
*
* @return a new SCA binding
*/
SCABinding createSCABinding();
DistributedSCABinding createDistributedSCABinding();
}

View file

@ -6,35 +6,40 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apache.tuscany.sca.assembly.impl;
import org.apache.tuscany.sca.assembly.DistributedSCABinding;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
/**
* A factory for the SCA binding model.
*
*
* @version $Rev$ $Date$
*/
public class SCABindingFactoryImpl implements SCABindingFactory {
public SCABindingFactoryImpl (){
}
public SCABinding createSCABinding() {
return new SCABindingImpl();
}
public DistributedSCABinding createDistributedSCABinding() {
return new DistributedSCABindingImpl();
}
}

View file

@ -25,8 +25,9 @@ import java.util.logging.Logger;
import org.apache.tuscany.sca.assembly.DistributedSCABinding;
import org.apache.tuscany.sca.assembly.OptimizableBinding;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.impl.DistributedSCABindingImpl;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.InvocationChain;
@ -61,6 +62,7 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
private BindingProviderFactory<DistributedSCABinding> distributedProviderFactory = null;
private ReferenceBindingProvider distributedProvider = null;
private SCABindingFactory scaBindingFactory;
public RuntimeSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints,
RuntimeComponent component,
@ -69,6 +71,8 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
this.component = component;
this.reference = reference;
this.binding = binding;
this.scaBindingFactory =
extensionPoints.getExtensionPoint(FactoryExtensionPoint.class).getFactory(SCABindingFactory.class);
// look to see if a distributed SCA binding implementation has
// been included on the classpath. This will be needed by the
@ -149,7 +153,7 @@ public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvi
}
// create the remote provider
DistributedSCABinding distributedBinding = new DistributedSCABindingImpl();
DistributedSCABinding distributedBinding = scaBindingFactory.createDistributedSCABinding();
distributedBinding.setSCABinding(binding);
distributedProvider =

View file

@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apache.tuscany.sca.binding.sca.provider;
@ -23,8 +23,9 @@ import java.net.URI;
import org.apache.tuscany.sca.assembly.DistributedSCABinding;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.impl.DistributedSCABindingImpl;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.provider.BindingProviderFactory;
import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
@ -33,67 +34,69 @@ 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
*
* The sca service binding provider mediates between the twin requirements of
* local sca bindings and remote sca bindings. In the local case is does
* very little. When the sca binding model is set as being remote this binding will
* try and create a remote service endpoint for remote references to connect to
*
* @version $Rev$ $Date$
*/
public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider {
private RuntimeComponentService service;
private BindingProviderFactory<DistributedSCABinding> distributedProviderFactory;
private ServiceBindingProvider distributedProvider;
private DistributedSCABinding distributedBinding;
public RuntimeSCAServiceBindingProvider(ExtensionPointRegistry extensionPoints,
RuntimeComponent component,
RuntimeComponentService service,
SCABinding binding) {
this.service = service;
// if there is potentially a wire to this service that crosses the node boundary
if (service.getInterfaceContract().getInterface().isRemotable()) {
// 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
// been included on the classpath. This will be needed by the
// provider itself to do it's thing
ProviderFactoryExtensionPoint factoryExtensionPoint =
extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
distributedProviderFactory =
(BindingProviderFactory<DistributedSCABinding>)factoryExtensionPoint
.getProviderFactory(DistributedSCABinding.class);
// Check the things that will generally be required to set up a
.getProviderFactory(DistributedSCABinding.class);
// Check the things that will generally be required to set up a
// distributed sca domain reference provider. I.e. make sure that we have a
// - distributed implementation of the sca binding available
// - remotable interface on the service
if (distributedProviderFactory != null) {
URI serviceURI = null;
try {
serviceURI = new URI(binding.getURI());
} catch(Exception ex) {
}
if (RemoteBindingHelper.isTargetRemote() || ((serviceURI != null) && (serviceURI.isAbsolute()))) {
if (RemoteBindingHelper.isTargetRemote() || ((serviceURI != null) && (serviceURI.isAbsolute()))) {
SCABindingFactory scaBindingFactory =
extensionPoints.getExtensionPoint(FactoryExtensionPoint.class).getFactory(SCABindingFactory.class);
// create a nested provider to handle the remote case
distributedBinding = new DistributedSCABindingImpl();
distributedBinding = scaBindingFactory.createDistributedSCABinding();
distributedBinding.setSCABinding(binding);
distributedProvider =
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.
*
* will currently have the distributed domain set.
*
throw new IllegalStateException("No distributed domain available for component: "+
component.getName() +
" and service: " +
" and service: " +
service.getName());
*/
}
@ -102,11 +105,11 @@ public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider
* are marked as remote
throw new IllegalStateException("No distributed SCA binding available for component: "+
component.getName() +
" and service: " +
" and service: " +
service.getName());
*/
}
}
}
}
public InterfaceContract getBindingInterfaceContract() {
@ -124,7 +127,7 @@ public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider
public boolean supportsOneWayInvocation() {
return false;
}
public void start() {
if (distributedProvider != null) {
distributedProvider.start();
@ -135,7 +138,7 @@ public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider
if (distributedProvider != null) {
distributedProvider.stop();
}
if (distributedBinding != null) {
// reset the binding URI to null so that if the composite containing the component
// with the service/binding is restarted the binding will have the correct URI set
@ -147,9 +150,9 @@ public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider
}
} catch (Exception ex){
scaBinding.setURI(null);
}
}
}
}
}

View file

@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apace.tuscany.sca.binding.sca;
@ -29,12 +29,12 @@ import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint;
import org.apache.tuscany.sca.assembly.impl.SCABindingFactoryImpl;
import org.apache.tuscany.sca.assembly.xml.CompositeModelResolver;
import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.FactoryExtensionPoint;
import org.apache.tuscany.sca.policy.PolicyFactory;
import org.junit.Assert;
@ -48,62 +48,66 @@ import org.junit.Test;
* @version $Rev$ $Date$
*/
public class SCABindingTestCase {
private XMLInputFactory inputFactory;
private StAXArtifactProcessor<Object> staxProcessor;
private CompositeModelResolver resolver;
private StAXArtifactProcessor<Object> staxProcessor;
private CompositeModelResolver resolver;
private CompositeBuilder compositeBuilder;
private ExtensionPointRegistry extensionPoints;
@Before
public void init() throws Exception {
DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
public void init() throws Exception {
extensionPoints = new DefaultExtensionPointRegistry();
inputFactory = XMLInputFactory.newInstance();
StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
resolver = new CompositeModelResolver(null, null);
FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
PolicyFactory attachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class);
compositeBuilder = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder");
}
@Test
public void testSCABindingFactory() {
SCABindingFactory factory = new SCABindingFactoryImpl();
SCABindingFactory factory =
extensionPoints.getExtensionPoint(FactoryExtensionPoint.class).getFactory(SCABindingFactory.class);
Assert.assertNotNull(factory.createSCABinding());
Assert.assertNotNull(factory.createDistributedSCABinding());
}
@Test
@Test
@Ignore
public void testBuildModel() {
try{
InputStream is = getClass().getResourceAsStream("/Calculator.composite");
InputStream is = getClass().getResourceAsStream("/Calculator.composite");
XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
Composite composite = (Composite)staxProcessor.read(reader);
is.close();
Assert.assertNotNull(composite);
resolver.addModel(composite);
staxProcessor.resolve(composite, resolver);
compositeBuilder.build(composite, null, null);
SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0);
SCABinding serviceSCABinding = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0);
Assert.assertNotNull(referenceSCABinding);
Assert.assertNotNull(serviceSCABinding);
} catch (Exception ex) {
Assert.fail(ex.getMessage());
}
}
}

View file

@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apace.tuscany.sca.binding.sca.xml;
@ -40,7 +40,7 @@ import org.junit.Test;
/**
* Test reading/write WSDL interfaces.
*
*
* @version $Rev: 750765 $ $Date: 2009-03-06 04:36:04 +0000 (Fri, 06 Mar 2009) $
*/
public class WriteTestCase {

View file

@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* under the License.
*/
package org.apache.tuscany.sca.implementation.node.builder.impl;
@ -35,6 +35,7 @@ import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.assembly.Composite;
import org.apache.tuscany.sca.assembly.CompositeService;
import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
import org.apache.tuscany.sca.assembly.DistributedSCABinding;
import org.apache.tuscany.sca.assembly.SCABinding;
import org.apache.tuscany.sca.assembly.SCABindingFactory;
import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
@ -82,7 +83,7 @@ public class CalculateBindingURITestCase {
/**
* Create a composite containing a node component pointing to the
* given application composite.
*
*
* @param composite
* @return
*/
@ -107,16 +108,16 @@ public class CalculateBindingURITestCase {
/**
* Test that URI are generated in accordance with the Assembly Specification section 1.7.2.1 as
* follows. For the 3 parts that make up the URI;
*
*
* BaseURI / Component URI / Service Binding URI
*
*
* Test the following combinations for:
*
*
* NB. The short hand here, e.g. <service name="s1"> <binding.sca> <service name="s2"> means
* two services appear where the first has the sca binding specified.
*
* two services appear where the first has the sca binding specified.
*
* component service bindings
*
*
* http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca>
* --> http://myhost:8080/root/c1
* http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca> <service name="s2">
@ -128,10 +129,10 @@ public class CalculateBindingURITestCase {
* http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca uri="http://myhost:8080/b"> <service name="s2">
* --> http://myhost:8080/b
* http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca uri="../../b"> <service name="s2">
* --> http://myhost:8080/b
*
* --> http://myhost:8080/b
*
* top level composite service bindings
*
*
* http://myhost:8080/root / null / <service name="s1"> <binding.sca> <service name="s2">
* --> http://myhost:8080/root
* http://myhost:8080/root / null / <service name="s1"> <binding.sca> <service name="s2">
@ -142,9 +143,9 @@ public class CalculateBindingURITestCase {
* --> http://myhost:8080/root/b
* http://myhost:8080/root / null / <service name="s1"> <binding.sca uri="http://myhost:8080/b"> <service name="s2">
* --> http://myhost:8080/b
*
*
* nested composite service bindings
*
*
* http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca>
* --> http://myhost:8080/root/c1/c2
* http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca> <service name="s2">
@ -155,9 +156,9 @@ public class CalculateBindingURITestCase {
* --> http://myhost:8080/root/c1/c2/b
* http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca uri="http://myhost:8080/b"> <service name="s2">
* --> http://myhost:8080/b
*
*
* binding name duplication errors
*
*
* http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca> <binding.xyz>
* --> Error
* http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca name="b1"> <binding.xyz name="b1">
@ -523,7 +524,7 @@ public class CalculateBindingURITestCase {
// component service binding name error tests
//FIXME Need to find a better way to test these error cases as
// the composite builder now (intentionally) logs warnings instead of
// the composite builder now (intentionally) logs warnings instead of
// throwing exceptions
public void FIXMEtestComponentServiceBindingNameError1() {
Composite composite = createComponentServiceBinding();
@ -540,7 +541,7 @@ public class CalculateBindingURITestCase {
}
//FIXME Need to find a better way to test these error cases as
// the composite builder now (intentionally) logs warnings instead of
// the composite builder now (intentionally) logs warnings instead of
// throwing exceptions
public void FIXMEtestComponentServiceBindingNameError2() {
Composite composite = createComponentServiceBinding();
@ -563,6 +564,10 @@ public class CalculateBindingURITestCase {
public SCABinding createSCABinding() {
return new TestBindingImpl();
}
public DistributedSCABinding createDistributedSCABinding() {
return null;
}
}
public class TestBindingImpl implements SCABinding {