diff options
Diffstat (limited to 'java/sca/modules/assembly/src')
26 files changed, 395 insertions, 252 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java index cd71f06279..dbb1bab44b 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java @@ -19,9 +19,9 @@ package org.apache.tuscany.sca.assembly.builder; -import org.apache.tuscany.sca.assembly.AbstractContract; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -29,7 +29,7 @@ import org.apache.tuscany.sca.monitor.Monitor; * * @version $Rev$ $Date$ */ -public interface BindingBuilder { +public interface BindingBuilder<B extends Binding> { /** * Configure a binding. @@ -37,6 +37,8 @@ public interface BindingBuilder { * @param component The component for the binding's service or reference * @param contract The binding's service or reference */ - void build(Component component, AbstractContract contract, Binding binding, Monitor monitor); + void build(Component component, Contract contract, B binding, Monitor monitor); + + Class<B> getModelType(); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java deleted file mode 100644 index 0f1fee3c1d..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.assembly.builder; - -/** - * An extension that can be implemented by bindings to provide a binding builder. - * - * @version $Rev$ $Date$ - */ -public interface BindingBuilderExtension { - - /** - * Returns the binding builder. - * - * @return the binding builder - */ - BindingBuilder getBuilder(); - - /** - * Sets the binding builder. - * - * @param builder the binding builder - */ - void setBuilder(BindingBuilder builder); - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderExtensionPoint.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderExtensionPoint.java index 151da31af0..d20c28d61e 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderExtensionPoint.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderExtensionPoint.java @@ -19,6 +19,9 @@ package org.apache.tuscany.sca.assembly.builder; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; + /** * An extension point for Composite builders. * @@ -47,5 +50,17 @@ public interface CompositeBuilderExtensionPoint { * @return */ CompositeBuilder getCompositeBuilder(String id); + + void addBindingBuilder(BindingBuilder<?> bindingBuilder); + + <B extends Binding> BindingBuilder<B> getBindingBuilder(Class<B> bindingType); + + <B extends Binding> void removeBindingBuilder(BindingBuilder<B> builder); + + void addImplementationBuilder(ImplementationBuilder<?> implementationBuilder); + + <I extends Implementation> ImplementationBuilder<I> getImplementationBuilder(Class<I> implementationType); + + <I extends Implementation> void removeImplementationBuilder(ImplementationBuilder<I> builder); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java index c98e31d95b..7fdd3b19f5 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultCompositeBuilderExtensionPoint.java @@ -27,7 +27,11 @@ import java.util.Map; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -46,6 +50,9 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx private ExtensionPointRegistry registry; private final Map<String, CompositeBuilder> builders = new HashMap<String, CompositeBuilder>(); + private final Map<Class<?>, BindingBuilder> bindingBuilders = new HashMap<Class<?>, BindingBuilder>(); + private final Map<Class<?>, ImplementationBuilder> implementationBuilders = + new HashMap<Class<?>, ImplementationBuilder>(); private boolean loaded; public DefaultCompositeBuilderExtensionPoint(ExtensionPointRegistry registry) { @@ -90,19 +97,84 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx Map<String, String> attributes = builderDeclaration.getAttributes(); String id = attributes.get("id"); - CompositeBuilder builder = - new LazyCompositeBuilder(registry, id, builderDeclaration, this, factories, mapper); + CompositeBuilder builder = new LazyCompositeBuilder(id, builderDeclaration, this, factories, mapper); builders.put(id, builder); } + + try { + builderDeclarations = serviceDiscovery.getServiceDeclarations(BindingBuilder.class); + } catch (Exception e) { + throw new IllegalStateException(e); + } + + for (ServiceDeclaration builderDeclaration : builderDeclarations) { + BindingBuilder<?> builder = new LazyBindingBuilder(builderDeclaration); + bindingBuilders.put(builder.getModelType(), builder); + } + + try { + builderDeclarations = serviceDiscovery.getServiceDeclarations(ImplementationBuilder.class); + } catch (Exception e) { + throw new IllegalStateException(e); + } + + for (ServiceDeclaration builderDeclaration : builderDeclarations) { + ImplementationBuilder<?> builder = new LazyImplementationBuilder(builderDeclaration); + implementationBuilders.put(builder.getModelType(), builder); + } + + } + + public void addBindingBuilder(BindingBuilder<?> bindingBuilder) { + bindingBuilders.put(bindingBuilder.getModelType(), bindingBuilder); + } + + public void addImplementationBuilder(ImplementationBuilder<?> implementationBuilder) { + implementationBuilders.put(implementationBuilder.getModelType(), implementationBuilder); + } + + public <B extends Binding> BindingBuilder<B> getBindingBuilder(Class<B> bindingType) { + if (bindingType.isInterface()) { + return (BindingBuilder<B>)bindingBuilders.get(bindingType); + } + Class<?>[] classes = bindingType.getInterfaces(); + for (Class<?> i : classes) { + BindingBuilder<B> builder = (BindingBuilder<B>)bindingBuilders.get(i); + if (builder != null) { + return builder; + } + } + return null; + } + + public <I extends Implementation> ImplementationBuilder<I> getImplementationBuilder(Class<I> implementationType) { + if (implementationType.isInterface()) { + return (ImplementationBuilder<I>)implementationBuilders.get(implementationType); + } + Class<?>[] classes = implementationType.getInterfaces(); + for (Class<?> i : classes) { + ImplementationBuilder<I> builder = (ImplementationBuilder<I>)implementationBuilders.get(i); + if (builder != null) { + return builder; + } + } + return null; + } + + public <B extends Binding> void removeBindingBuilder(BindingBuilder<B> builder) { + bindingBuilders.remove(builder.getModelType()); + } + + public <I extends Implementation> void removeImplementationBuilder(ImplementationBuilder<I> builder) { + implementationBuilders.remove(builder.getModelType()); } /** * A wrapper around a composite builder allowing lazy * loading and initialization of implementation providers. */ - private static class LazyCompositeBuilder implements CompositeBuilder, CompositeBuilderTmp { + private class LazyCompositeBuilder implements CompositeBuilder, CompositeBuilderTmp { - private ExtensionPointRegistry registry; private FactoryExtensionPoint factories; private InterfaceContractMapper mapper; private String id; @@ -110,13 +182,11 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx private CompositeBuilder builder; private CompositeBuilderExtensionPoint builders; - private LazyCompositeBuilder(ExtensionPointRegistry registry, - String id, + private LazyCompositeBuilder(String id, ServiceDeclaration factoryDeclaration, CompositeBuilderExtensionPoint builders, FactoryExtensionPoint factories, InterfaceContractMapper mapper) { - this.registry = registry; this.id = id; this.builderDeclaration = factoryDeclaration; this.builders = builders; @@ -170,4 +240,106 @@ public class DefaultCompositeBuilderExtensionPoint implements CompositeBuilderEx } + private class LazyBindingBuilder implements BindingBuilder { + private ServiceDeclaration sd; + private String model; + private BindingBuilder<?> builder; + private Class<?> modelType; + + /** + * @param sd + */ + public LazyBindingBuilder(ServiceDeclaration sd) { + super(); + this.sd = sd; + this.model = sd.getAttributes().get("model"); + } + + public void build(Component component, Contract contract, Binding binding, Monitor monitor) { + getBuilder().build(component, contract, binding, monitor); + } + + public Class getModelType() { + if (modelType == null) { + try { + modelType = sd.loadClass(model); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + private synchronized BindingBuilder getBuilder() { + if (builder == null) { + try { + Class<?> builderClass = sd.loadClass(); + try { + Constructor<?> constructor = builderClass.getConstructor(ExtensionPointRegistry.class); + builder = (BindingBuilder)constructor.newInstance(registry); + } catch (NoSuchMethodException e) { + Constructor<?> constructor = builderClass.getConstructor(); + builder = (BindingBuilder)constructor.newInstance(); + + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return builder; + } + + } + + private class LazyImplementationBuilder implements ImplementationBuilder { + private ServiceDeclaration sd; + private String model; + private ImplementationBuilder<?> builder; + private Class<?> modelType; + + /** + * @param sd + */ + public LazyImplementationBuilder(ServiceDeclaration sd) { + super(); + this.sd = sd; + this.model = sd.getAttributes().get("model"); + } + + public void build(Component component, Implementation implementation, Monitor monitor) { + getBuilder().build(component, implementation, monitor); + } + + public Class getModelType() { + if (modelType == null) { + try { + modelType = sd.loadClass(model); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + private synchronized ImplementationBuilder getBuilder() { + if (builder == null) { + try { + Class<?> builderClass = sd.loadClass(); + try { + Constructor<?> constructor = builderClass.getConstructor(ExtensionPointRegistry.class); + builder = (ImplementationBuilder)constructor.newInstance(registry); + } catch (NoSuchMethodException e) { + Constructor<?> constructor = builderClass.getConstructor(); + builder = (ImplementationBuilder)constructor.newInstance(); + + } + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return builder; + } + + } + } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java index d2fae4d24a..2c2b3c1cba 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java @@ -20,14 +20,24 @@ package org.apache.tuscany.sca.assembly.builder; import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.monitor.Monitor; /** - * Interface for Component Pre Processors. + * A builder that handles any build-time configuration needed by implementations. * * @version $Rev$ $Date$ */ -public interface ComponentPreProcessor { +public interface ImplementationBuilder<I extends Implementation> { - void preProcess(Component component); + /** + * Configure a component implementation. + * + * @param component The component + * @param contract The implementation + */ + void build(Component component, I implmentation, Monitor monitor); + + Class<I> getModelType(); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java index 4b83606116..b512743972 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java @@ -39,6 +39,7 @@ import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -67,12 +68,15 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { protected InterfaceContractMapper interfaceContractMapper; protected DocumentBuilderFactory documentBuilderFactory; protected TransformerFactory transformerFactory; + protected CompositeBuilderExtensionPoint builders; - protected BaseBuilderImpl(AssemblyFactory assemblyFactory, + protected BaseBuilderImpl(CompositeBuilderExtensionPoint builders, + AssemblyFactory assemblyFactory, SCABindingFactory scaBindingFactory, DocumentBuilderFactory documentBuilderFactory, TransformerFactory transformerFactory, InterfaceContractMapper interfaceContractMapper) { + this.builders = builders; this.assemblyFactory = assemblyFactory; this.scaBindingFactory = scaBindingFactory; this.documentBuilderFactory = documentBuilderFactory; @@ -85,6 +89,7 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { * @param registry */ protected BaseBuilderImpl(ExtensionPointRegistry registry) { + this.builders = registry.getExtensionPoint(CompositeBuilderExtensionPoint.class); FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class); this.assemblyFactory = factoryExtensionPoint.getFactory(AssemblyFactory.class); this.scaBindingFactory = factoryExtensionPoint.getFactory(SCABindingFactory.class); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java index 23493599bc..9d9b3165eb 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java @@ -18,21 +18,14 @@ */ package org.apache.tuscany.sca.assembly.builder.impl; -import java.net.URI; -import java.util.HashMap; -import java.util.List; -import java.util.Map; import java.util.logging.Logger; import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.TransformerFactory; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.CompositeService; @@ -42,10 +35,8 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilderTmp; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.assembly.builder.ImplementationBuilder; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -55,8 +46,6 @@ import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.policy.PolicySubject; /** @@ -74,6 +63,7 @@ public class ComponentBuilderImpl { private AssemblyFactory assemblyFactory; private SCABindingFactory scaBindingFactory; private InterfaceContractMapper interfaceContractMapper; + private CompositeBuilderExtensionPoint builders; public ComponentBuilderImpl(ExtensionPointRegistry registry) { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); @@ -85,6 +75,8 @@ public class ComponentBuilderImpl { scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); + + builders = registry.getExtensionPoint(CompositeBuilderExtensionPoint.class); } public void setComponentTypeBuilder(ComponentTypeBuilderImpl componentTypeBuilder){ @@ -99,8 +91,12 @@ public class ComponentBuilderImpl { // do any required pre-processing on the implementation // what does this do? - if (component.getImplementation() instanceof ComponentPreProcessor) { - ((ComponentPreProcessor)component.getImplementation()).preProcess(component); + Implementation impl = component.getImplementation(); + if (impl != null) { + ImplementationBuilder builder = builders.getImplementationBuilder(impl.getClass()); + if (builder != null) { + builder.build(component, impl, monitor); + } } // create the component type for this component diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java index a44c5b262a..34917a3cd9 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java @@ -24,10 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.TransformerFactory; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.ComponentReference; @@ -38,14 +34,13 @@ import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.ImplementationBuilder; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -55,19 +50,8 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ComponentConfigurationBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - @Deprecated - public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, scaBindingFactory, null, null, interfaceContractMapper); - } - - public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - DocumentBuilderFactory documentBuilderFactory, - TransformerFactory transformerFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper); + public ComponentConfigurationBuilderImpl(ExtensionPointRegistry registry) { + super(registry); } public String getID() { @@ -158,9 +142,13 @@ public class ComponentConfigurationBuilderImpl extends BaseBuilderImpl implement component.setAutowire(composite.getAutowire()); } - if (component.getImplementation() instanceof ComponentPreProcessor) { - ((ComponentPreProcessor)component.getImplementation()).preProcess(component); - } + Implementation impl = component.getImplementation(); + if (impl != null) { + ImplementationBuilder builder = builders.getImplementationBuilder(impl.getClass()); + if (builder != null) { + builder.build(component, impl, monitor); + } + } // Index implementation properties, services and references Map<String, Service> services = new HashMap<String, Service>(); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java index ca9e55662a..a9400d95ef 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java @@ -24,9 +24,11 @@ import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.assembly.builder.BindingBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; @@ -38,9 +40,12 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { - public ComponentReferenceBindingBuilderImpl() { - } + private CompositeBuilderExtensionPoint builders; + public ComponentReferenceBindingBuilderImpl(ExtensionPointRegistry registry) { + this.builders = registry.getExtensionPoint(CompositeBuilderExtensionPoint.class); + } + public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { buildReferenceBindings(composite, monitor); } @@ -55,11 +60,9 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { for (Component component : composite.getComponents()) { for (ComponentReference componentReference : component.getReferences()) { for (Binding binding : componentReference.getBindings()) { - if (binding instanceof BindingBuilderExtension) { - ((BindingBuilderExtension)binding).getBuilder().build(component, - componentReference, - binding, - monitor); + BindingBuilder builder = builders.getBindingBuilder(binding.getClass()); + if (builder != null) { + builder.build(component, componentReference, binding, monitor); } } } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java index f83ca90331..f865c36263 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; @@ -39,9 +38,9 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicySet; @@ -58,9 +57,8 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI //boolean useNew = true; boolean useNew = false; - public ComponentReferenceEndpointReferenceBuilderImpl(AssemblyFactory assemblyFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, null, null, null, interfaceContractMapper); + public ComponentReferenceEndpointReferenceBuilderImpl(ExtensionPointRegistry registry) { + super(registry); } public String getID() { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionBuilderImpl.java index fb723bf43c..b4f3516bd3 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionBuilderImpl.java @@ -31,6 +31,8 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; @@ -42,8 +44,9 @@ import org.apache.tuscany.sca.monitor.Monitor; public class ComponentReferencePromotionBuilderImpl implements CompositeBuilder { private AssemblyFactory assemblyFactory; - public ComponentReferencePromotionBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; + public ComponentReferencePromotionBuilderImpl(ExtensionPointRegistry registry) { + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = factories.getFactory(AssemblyFactory.class); } public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java index f6b6561bdd..53221fd3c5 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java @@ -23,19 +23,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Wire; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -45,9 +42,8 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - public ComponentReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, null, null, null, interfaceContractMapper); + public ComponentReferenceWireBuilderImpl(ExtensionPointRegistry registry) { + super(registry); } public String getID() { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java index 613b39171f..f8d25887cf 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java @@ -25,9 +25,10 @@ import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.builder.BindingBuilder; -import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; @@ -38,8 +39,10 @@ import org.apache.tuscany.sca.monitor.Monitor; * @version $Rev$ $Date$ */ public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { - - public ComponentServiceBindingBuilderImpl() { + private CompositeBuilderExtensionPoint builders; + + public ComponentServiceBindingBuilderImpl(ExtensionPointRegistry registry) { + this.builders = registry.getExtensionPoint(CompositeBuilderExtensionPoint.class); } public String getID() { @@ -64,11 +67,9 @@ public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { for (Component component : composite.getComponents()) { for (ComponentService componentService : component.getServices()) { for (Binding binding : componentService.getBindings()) { - if (binding instanceof BindingBuilderExtension) { - BindingBuilder builder = ((BindingBuilderExtension)binding).getBuilder(); - if (builder != null) { - builder.build(component, componentService, binding, monitor); - } + BindingBuilder builder = builders.getBindingBuilder(binding.getClass()); + if (builder != null) { + builder.build(component, componentService, binding, monitor); } } } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java index 6750643c6f..f419432b1f 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentTypeBuilderImpl.java @@ -37,7 +37,7 @@ import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; @@ -64,6 +64,7 @@ public class ComponentTypeBuilderImpl { private AssemblyFactory assemblyFactory; private SCABindingFactory scaBindingFactory; private InterfaceContractMapper interfaceContractMapper; + private CompositeBuilderExtensionPoint builders; public ComponentTypeBuilderImpl(ExtensionPointRegistry registry) { @@ -76,6 +77,7 @@ public class ComponentTypeBuilderImpl { scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); + builders = registry.getExtensionPoint(CompositeBuilderExtensionPoint.class); } public void setComponentBuilder(ComponentBuilderImpl componentBuilder){ diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java index 1c1047da3e..417c0b60e0 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java @@ -21,15 +21,12 @@ package org.apache.tuscany.sca.assembly.builder.impl; import java.util.List; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -44,15 +41,8 @@ import org.apache.tuscany.sca.monitor.Monitor; public class CompositeBindingConfigurationBuilderImpl extends CompositeBindingURIBuilderImpl implements CompositeBuilder { - public CompositeBindingConfigurationBuilderImpl(FactoryExtensionPoint factories, InterfaceContractMapper mapper) { - super(factories.getFactory(AssemblyFactory.class), factories.getFactory(SCABindingFactory.class), null, null, - mapper); - } - - public CompositeBindingConfigurationBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, scaBindingFactory, null, null, interfaceContractMapper); + public CompositeBindingConfigurationBuilderImpl(ExtensionPointRegistry registry) { + super(registry); } public String getID() { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java index cf48c49add..b2deb54d1f 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java @@ -26,10 +26,7 @@ import java.util.List; import java.util.Map; import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.TransformerFactory; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentProperty; @@ -40,13 +37,12 @@ import org.apache.tuscany.sca.assembly.Contract; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderTmp; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -56,19 +52,8 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements CompositeBuilder, CompositeBuilderTmp { - @Deprecated - public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, scaBindingFactory, null, null, interfaceContractMapper); - } - - public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - DocumentBuilderFactory documentBuilderFactory, - TransformerFactory transformerFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper); + public CompositeBindingURIBuilderImpl(ExtensionPointRegistry registry) { + super(registry); } public String getID() { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java index b42987c6db..275973023f 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java @@ -23,20 +23,17 @@ import java.util.Map; import java.util.logging.Logger; import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.TransformerFactory; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderTmp; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.PolicyFactory; /** * A builder that handles the configuration of the components inside a composite @@ -66,74 +63,41 @@ public class CompositeBuilderImpl implements CompositeBuilder, CompositeBuilderT private CompositeBuilder componentReferenceEndpointReferenceBuilder; private CompositeBuilder componentServiceEndpointBuilder; - //private CompositeBuilder endpointReferenceBuilder; - - public CompositeBuilderImpl(FactoryExtensionPoint factories, InterfaceContractMapper mapper) { - this(factories.getFactory(AssemblyFactory.class), factories.getFactory(SCABindingFactory.class), factories - .getFactory(PolicyFactory.class), factories.getFactory(DocumentBuilderFactory.class), factories - .getFactory(TransformerFactory.class), mapper); - } - - /** - * Constructs a new composite builder. - * - * @param assemblyFactory - * @param scaBindingFactory - * @param endpointFactory - * @param intentAttachPointTypeFactory - * @param interfaceContractMapper - * @param policyDefinitions - * @param monitor - */ - @Deprecated - public CompositeBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - PolicyFactory intentAttachPointTypeFactory, - InterfaceContractMapper interfaceContractMapper) { - this(assemblyFactory, scaBindingFactory, intentAttachPointTypeFactory, null, null, interfaceContractMapper); - } + private CompositeBuilderExtensionPoint builders; + /** * Constructs a new composite builder. - * - * @param assemblyFactory - * @param scaBindingFactory - * @param endpointFactory - * @param intentAttachPointTypeFactory - * @param interfaceContractMapper - * @param policyDefinitions - * @param monitor + * + * @param registry */ - public CompositeBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - PolicyFactory intentAttachPointTypeFactory, - DocumentBuilderFactory documentBuilderFactory, - TransformerFactory transformerFactory, - InterfaceContractMapper interfaceContractMapper) { - - compositeIncludeBuilder = new CompositeIncludeBuilderImpl(assemblyFactory); - componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, interfaceContractMapper); + public CompositeBuilderImpl(ExtensionPointRegistry registry) { + + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.builders = registry.getExtensionPoint(CompositeBuilderExtensionPoint.class); + AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); + + compositeIncludeBuilder = new CompositeIncludeBuilderImpl(); + componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(registry); //componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, endpointFactory); - componentReferencePromotionBuilder = new ComponentReferencePromotionBuilderImpl(assemblyFactory); + componentReferencePromotionBuilder = new ComponentReferencePromotionBuilderImpl(registry); //compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory); compositeCloneBuilder = new CompositeCloneBuilderImpl(); componentConfigurationBuilder = - new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, - transformerFactory, interfaceContractMapper); - compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory); - compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(assemblyFactory); + new ComponentConfigurationBuilderImpl(registry); + compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(registry); + compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(registry); compositeBindingURIBuilder = - new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, - transformerFactory, interfaceContractMapper); + new CompositeBindingURIBuilderImpl(registry); //componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory); //compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory); - compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, interfaceContractMapper); - compositePolicyBuilder = new CompositePolicyBuilderImpl(assemblyFactory, interfaceContractMapper); - componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(); - componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(); + compositePromotionBuilder = new CompositePromotionBuilderImpl(registry); + compositePolicyBuilder = new CompositePolicyBuilderImpl(registry); + componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(registry); + componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(registry); componentReferenceEndpointReferenceBuilder = - new ComponentReferenceEndpointReferenceBuilderImpl(assemblyFactory, interfaceContractMapper); + new ComponentReferenceEndpointReferenceBuilderImpl(registry); componentServiceEndpointBuilder = new ComponentServiceEndpointBuilderImpl(assemblyFactory); //endpointReferenceBuilder = new EndpointReference2BuilderImpl(assemblyFactory, interfaceContractMapper); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java index 451c2e0212..1bd52cbe6f 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java @@ -22,17 +22,15 @@ package org.apache.tuscany.sca.assembly.builder.impl; import java.util.HashSet; import java.util.Set; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; /** * Implementation of a CompositeBuilder. @@ -41,10 +39,7 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class CompositeIncludeBuilderImpl implements CompositeBuilder { - private AssemblyFactory assemblyFactory; - - public CompositeIncludeBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; + public CompositeIncludeBuilderImpl() { } public String getID() { @@ -69,6 +64,15 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { visited.add(composite); for (Composite included : composite.getIncludes()) { + if(included.isLocal() && !composite.isLocal()) { + // ASM60041 + Monitor.error(monitor, + this, + "assembly-validation-messages", + "IllegalCompositeIncusion", + composite.getName().toString(), + included.getName().toString()); + } Composite fusedComposite = fuseInclude(included, visited, monitor); if (fusedComposite != null) { composite.getComponents().addAll(fusedComposite.getComponents()); @@ -76,8 +80,6 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { composite.getReferences().addAll(fusedComposite.getReferences()); composite.getProperties().addAll(fusedComposite.getProperties()); composite.getWires().addAll(fusedComposite.getWires()); - composite.getPolicySets().addAll(fusedComposite.getPolicySets()); - composite.getRequiredIntents().addAll(fusedComposite.getRequiredIntents()); } } @@ -108,6 +110,8 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { private Composite fuseInclude(Composite include, Set<Composite> visited, Monitor monitor) { if (visited.contains(include)) { + // FIXME: [rfeng] Do we need to have a warning? I think it is fine to have Composite A + // include B and C while both B and C include D. Monitor.warning(monitor, this, "assembly-validation-messages", @@ -127,6 +131,17 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { // get the components etc. from any included composites for (Composite included : include.getIncludes()) { + if(included.isLocal() && !include.isLocal()) { + // ASM60041 + Monitor.error(monitor, + this, + "assembly-validation-messages", + "IllegalCompositeIncusion", + include.getName().toString(), + included.getName().toString()); + return null; + } + Composite fusedComposite = fuseInclude(included, visited, monitor); if (fusedComposite != null) { clone.getComponents().addAll(fusedComposite.getComponents()); @@ -134,8 +149,11 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { clone.getReferences().addAll(fusedComposite.getReferences()); clone.getProperties().addAll(fusedComposite.getProperties()); clone.getWires().addAll(fusedComposite.getWires()); - clone.getPolicySets().addAll(fusedComposite.getPolicySets()); - clone.getRequiredIntents().addAll(fusedComposite.getRequiredIntents()); + // FIXME: What should we do for the extensions + /* + clone.getExtensions().addAll(fusedComposite.getExtensions()); + clone.getAttributeExtensions().addAll(fusedComposite.getAttributeExtensions()); + */ } } @@ -144,10 +162,44 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { if (include.getAutowire() == Boolean.TRUE) { for (Component component : clone.getComponents()) { if (component.getAutowire() == null) { - component.setAutowire(true); + component.setAutowire(Boolean.TRUE); } } } + + // Merge the intents and policySets from the included composite into + // component/service/reference elements under the composite + for(Component component : clone.getComponents()) { + component.getRequiredIntents().addAll(include.getRequiredIntents()); + component.getPolicySets().addAll(include.getPolicySets()); + } + + for(Service service: clone.getServices()) { + service.getRequiredIntents().addAll(include.getRequiredIntents()); + service.getPolicySets().addAll(include.getPolicySets()); + } + + for(Reference reference: clone.getReferences()) { + reference.getRequiredIntents().addAll(include.getRequiredIntents()); + reference.getPolicySets().addAll(include.getPolicySets()); + } + + // process any composites referenced through implementation.composite + for (Component component : clone.getComponents()) { + + // recurse for composite implementations + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + try { + monitor.pushContext("Component: " + component.getName()); + fuseIncludes((Composite)implementation, monitor); + } finally { + monitor.popContext(); + } + } + } + + clone.getIncludes().clear(); // return the fused composite we have built up so far return clone; diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java index 9c7bd6b2d9..5d4a44f137 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java @@ -22,7 +22,6 @@ package org.apache.tuscany.sca.assembly.builder.impl; import java.util.HashSet; import java.util.Set; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; @@ -39,7 +38,6 @@ import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentMap; @@ -59,10 +57,6 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo super(registry); } - public CompositePolicyBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, null, null, null, interfaceContractMapper); - } - public String getID() { return "org.apache.tuscany.sca.assembly.builder.CompositePolicyBuilder"; } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java index b60ba68032..21c8596ea4 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java @@ -23,7 +23,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; @@ -35,9 +34,9 @@ import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; /** @@ -48,9 +47,8 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class CompositePromotionBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - public CompositePromotionBuilderImpl(AssemblyFactory assemblyFactory, - InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, null, null, null, interfaceContractMapper); + public CompositePromotionBuilderImpl(ExtensionPointRegistry registry) { + super(registry); } public String getID() { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java index 992d1915a3..702da49f54 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java @@ -33,6 +33,8 @@ import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; @@ -44,8 +46,9 @@ import org.apache.tuscany.sca.monitor.Monitor; public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuilder { private AssemblyFactory assemblyFactory; - public CompositeReferenceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; + public CompositeReferenceConfigurationBuilderImpl(ExtensionPointRegistry registry) { + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = factories.getFactory(AssemblyFactory.class); } public String getID() { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java index bf12b57a86..8fa2aeef1c 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java @@ -25,9 +25,11 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.assembly.builder.BindingBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; @@ -38,8 +40,10 @@ import org.apache.tuscany.sca.monitor.Monitor; * @version $Rev$ $Date$ */ public class CompositeServiceBindingBuilderImpl implements CompositeBuilder { + private CompositeBuilderExtensionPoint builders; - public CompositeServiceBindingBuilderImpl() { + public CompositeServiceBindingBuilderImpl(ExtensionPointRegistry registry) { + this.builders = registry.getExtensionPoint(CompositeBuilderExtensionPoint.class); } public String getID() { @@ -63,9 +67,10 @@ public class CompositeServiceBindingBuilderImpl implements CompositeBuilder { // find all the composite service bindings for (Service service : composite.getServices()) { for (Binding binding : service.getBindings()) { - if (binding instanceof BindingBuilderExtension) { + BindingBuilder builder = builders.getBindingBuilder(binding.getClass()); + if (builder != null) { Component component = ServiceConfigurationUtil.getPromotedComponent((CompositeService)service); - ((BindingBuilderExtension)binding).getBuilder().build(component, service, binding, monitor); + builder.build(component, service, binding, monitor); } } } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java index bed289c887..9bbfabf12a 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java @@ -31,6 +31,8 @@ import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.monitor.Monitor; @@ -42,8 +44,9 @@ import org.apache.tuscany.sca.monitor.Monitor; public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilder { private AssemblyFactory assemblyFactory; - public CompositeServiceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) { - this.assemblyFactory = assemblyFactory; + public CompositeServiceConfigurationBuilderImpl(ExtensionPointRegistry registry) { + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = factories.getFactory(AssemblyFactory.class); } public String getID() { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java index f59dc3dae9..5084e50622 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java @@ -80,7 +80,7 @@ public class ModelBuilderImpl implements CompositeBuilder, CompositeBuilderTmp { MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); Monitor monitor = monitorFactory.createMonitor(); - compositeIncludeBuilder = new CompositeIncludeBuilderImpl(assemblyFactory); + compositeIncludeBuilder = new CompositeIncludeBuilderImpl(); compositeCloneBuilder = new CompositeCloneBuilderImpl(); componentTypeBuilder = new ComponentTypeBuilderImpl(registry); diff --git a/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties b/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties index d5915393f7..61b61279de 100644 --- a/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties +++ b/java/sca/modules/assembly/src/main/resources/assembly-validation-messages.properties @@ -61,4 +61,5 @@ ReferenceInterfaceNotSubSet = Interface of composite reference {0} must be compa ServiceInterfaceNotSubSet = Interface of composite service {0} must be subset of the interface declared by promoted component service. NoComponentReferenceTarget = No target services found for the component reference to be autowired: {0} NoTypeForComponentProperty = No type specified on component property: Component = {0} Property = {1} -URLSyntaxException = URLSyntaxException when creating binding URI at component = {0} service = {1} binding = {2}
\ No newline at end of file +URLSyntaxException = URLSyntaxException when creating binding URI at component = {0} service = {1} binding = {2} +IllegalCompositeIncusion = Local Composite {0} cannot include a non-local composite {1}
\ No newline at end of file diff --git a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java index d33ad3ccef..57c6081859 100644 --- a/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java +++ b/java/sca/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java @@ -77,7 +77,7 @@ public class CompositeBuilderTestCase { c.setName(new QName("http://foo", "C")); c.getIncludes().add(c1); - new CompositeIncludeBuilderImpl(null).build(c, null, monitor); + new CompositeIncludeBuilderImpl().build(c, null, monitor); assertTrue(c.getComponents().get(0).getName().equals("a")); assertTrue(c.getComponents().get(1).getName().equals("b")); |