summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder')
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java54
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderContext.java107
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderExtensionPoint.java149
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java51
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java45
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ContractBuilder.java37
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java479
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java50
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Messages.java31
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java84
-rw-r--r--sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/WireBuilder.java39
11 files changed, 1126 insertions, 0 deletions
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java
new file mode 100644
index 0000000000..8c56385c9e
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+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.Contract;
+
+/**
+ * A builder that handles any build-time configuration needed by bindings.
+ *
+ * @version $Rev$ $Date$
+ * @tuscany.spi.extension.inheritfrom
+ */
+public interface BindingBuilder<B extends Binding> {
+
+ /**
+ * Configure a binding.
+ *
+ * @param component The component for the binding's service or reference
+ * @param contract The binding's service or reference
+ * @param context The context for the builder
+ * @param rebuild Set true to have derived data in the binding rebuilt
+ * caching can cause problems in the late binding case so we
+ * need to be able to remove cached data
+ */
+ void build(Component component, Contract contract, B binding, BuilderContext context, boolean rebuild);
+
+ /**
+ * Get QName of the binding type
+ * @return The binding type
+ */
+ QName getBindingType();
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderContext.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderContext.java
new file mode 100644
index 0000000000..374c36c1f5
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderContext.java
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.Definitions;
+import org.apache.tuscany.sca.monitor.DefaultMonitorFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+
+/**
+ * Context for builders
+ * @tuscany.spi.extension.asclient
+ */
+public class BuilderContext {
+ protected Definitions definitions;
+ protected Map<QName, List<String>> bindingBaseURIs = Collections.emptyMap();
+ protected Monitor monitor;
+
+ /**
+ * @param definitions
+ * @param bindingBaseURIs
+ * @param monitor
+ */
+ public BuilderContext(Definitions definitions, Map<QName, List<String>> bindingBaseURIs, Monitor monitor) {
+ super();
+ this.definitions = definitions;
+ if (bindingBaseURIs != null) {
+ this.bindingBaseURIs = bindingBaseURIs;
+ }
+ this.monitor = monitor;
+ }
+
+ /**
+ * Create a builder context with the monitor
+ * @param monitor
+ */
+ public BuilderContext(Monitor monitor) {
+ super();
+ this.monitor = monitor;
+ }
+
+ /**
+ * Create a builder context with the extension point registry
+ * @param registry
+ */
+ public BuilderContext(ExtensionPointRegistry registry) {
+ super();
+ MonitorFactory monitorFactory =
+ registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class);
+ this.monitor = monitorFactory.createMonitor();
+ }
+
+ /**
+ * Create a builder context with a default monitor
+ */
+ public BuilderContext() {
+ super();
+ this.monitor = new DefaultMonitorFactory().createMonitor();
+ }
+
+ public Monitor getMonitor() {
+ return monitor;
+ }
+
+ public Monitor setMonitor(Monitor monitor) {
+ Monitor old = this.monitor;
+ this.monitor = monitor;
+ return old;
+ }
+
+ public Definitions getDefinitions() {
+ return definitions;
+ }
+
+ public Map<QName, List<String>> getBindingBaseURIs() {
+ return bindingBaseURIs;
+ }
+
+ public void setDefinitions(Definitions definitions) {
+ this.definitions = definitions;
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderExtensionPoint.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderExtensionPoint.java
new file mode 100644
index 0000000000..14ae2042d3
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BuilderExtensionPoint.java
@@ -0,0 +1,149 @@
+/*
+ * 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;
+
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Implementation;
+
+/**
+ * An extension point for Composite builders.
+ *
+ * @version $Rev$ $Date$
+ * @tuscany.spi.extension.asclient
+ */
+public interface BuilderExtensionPoint {
+
+ /**
+ * Adds a contract builder.
+ *
+ * @param compositeBuilder
+ */
+ void addContractBuilder(ContractBuilder contractBuilder);
+
+ /**
+ * Removes a contract builder.
+ *
+ * @param compositeBuilder
+ */
+ void removeContractBuilder(ContractBuilder contractBuilder);
+
+ /**
+ * Returns the contract builder
+ *
+ * @param id
+ * @return
+ */
+ ContractBuilder getContractBuilder();
+
+ /**
+ * Adds a composite builder.
+ *
+ * @param compositeBuilder
+ */
+ void addCompositeBuilder(CompositeBuilder compositeBuilder);
+
+ /**
+ * Removes a composite builder.
+ *
+ * @param compositeBuilder
+ */
+ void removeCompositeBuilder(CompositeBuilder compositeBuilder);
+
+ /**
+ * Returns the composite builder with the given id.
+ *
+ * @param id
+ * @return
+ */
+ CompositeBuilder getCompositeBuilder(String id);
+
+ /**
+ * Add a binding builder
+ * @param bindingBuilder
+ */
+ void addBindingBuilder(BindingBuilder<?> bindingBuilder);
+
+ /**
+ * Look up a binding builder by the binding type
+ * @param <B>
+ * @param bindingType
+ * @return
+ */
+ <B extends Binding> BindingBuilder<B> getBindingBuilder(QName bindingType);
+
+ /**
+ * Remove a binding builder
+ * @param <B>
+ * @param builder
+ */
+ <B extends Binding> void removeBindingBuilder(BindingBuilder<B> builder);
+
+ /**
+ * Add an implementation builder
+ * @param implementationBuilder
+ */
+ void addImplementationBuilder(ImplementationBuilder<?> implementationBuilder);
+
+ /**
+ * Look up an implementation builder by implementation type
+ * @param <I>
+ * @param implementationType
+ * @return
+ */
+ <I extends Implementation> ImplementationBuilder<I> getImplementationBuilder(QName implementationType);
+
+ /**
+ * Remove an implementation builder
+ * @param <I>
+ * @param builder
+ */
+ <I extends Implementation> void removeImplementationBuilder(ImplementationBuilder<I> builder);
+
+ /**
+ * Add a policy builder
+ * @param policyBuilder
+ */
+ void addPolicyBuilder(PolicyBuilder<?> policyBuilder);
+
+ /**
+ * Look up a Policy builder by the Policy type
+ * @param <P>
+ * @param policyType
+ * @return
+ */
+ <P> PolicyBuilder<P> getPolicyBuilder(QName policyType);
+
+ /**
+ * Remove a Policy builder
+ * @param <P>
+ * @param builder
+ */
+ <P> void removePolicyBuilder(PolicyBuilder<P> builder);
+
+ /**
+ * Get a collection of policy builders
+ * @return
+ */
+ public Collection<PolicyBuilder> getPolicyBuilders();
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java
new file mode 100644
index 0000000000..50bf10f54a
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java
@@ -0,0 +1,51 @@
+/*
+ * 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;
+
+import org.apache.tuscany.sca.assembly.Composite;
+
+/**
+ * A builder that handles the configuration of the components inside a
+ * composite and the wiring of component references to component services.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeBuilder {
+
+ /**
+ * Returns the ID of the builder.
+ *
+ * @return An ID that identifies the builder
+ */
+ String getID();
+
+ /**
+ * Build a composite.
+ *
+ * @param composite The composite
+ * @param context The builder context
+ * @return The composite built from the original one. In most cases, it is the same as the orginal one as
+ * most builders only change the content of the composite.
+ *
+ * @throws CompositeBuilderException
+ */
+ Composite build(Composite composite, BuilderContext context) throws CompositeBuilderException;
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java
new file mode 100644
index 0000000000..5a2015f55e
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+/**
+ * Reports a composite builder exception.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeBuilderException extends Exception {
+ private static final long serialVersionUID = -8916323176803443856L;
+
+ public CompositeBuilderException() {
+ }
+
+ public CompositeBuilderException(String message) {
+ super(message);
+ }
+
+ public CompositeBuilderException(Throwable cause) {
+ super(cause);
+ }
+
+ public CompositeBuilderException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ContractBuilder.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ContractBuilder.java
new file mode 100644
index 0000000000..99a58dc1c8
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ContractBuilder.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.assembly.builder;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * A builder that builds WSDL versions of component contracts so that the
+ * component contracts can be compared with binding contracts in a generic way.
+ * The generic interface format defined by the Assembly spec is WSDL 1.1
+ */
+public interface ContractBuilder {
+
+ /**
+ * Build the WSDL version of the Interface Contract
+ */
+ boolean build(InterfaceContract interfaceContract, BuilderContext context);
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java
new file mode 100644
index 0000000000..8b037a7534
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultBuilderExtensionPoint.java
@@ -0,0 +1,479 @@
+/*
+ * 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;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+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.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+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.LifeCycleListener;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+
+/**
+ * Default implementation of a provider factory extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultBuilderExtensionPoint implements BuilderExtensionPoint, LifeCycleListener {
+
+ private ExtensionPointRegistry registry;
+ private final Map<String, CompositeBuilder> builders = new HashMap<String, CompositeBuilder>();
+ private final Map<QName, BindingBuilder> bindingBuilders = new HashMap<QName, BindingBuilder>();
+ private final Map<QName, ImplementationBuilder> implementationBuilders =
+ new HashMap<QName, ImplementationBuilder>();
+ private final Map<QName, PolicyBuilder> policyBuilders = new HashMap<QName, PolicyBuilder>();
+ private ContractBuilder contractBuilder = null;
+
+ private boolean loaded;
+
+ public DefaultBuilderExtensionPoint(ExtensionPointRegistry registry) {
+ this.registry = registry;
+ }
+
+ public void start() {
+ }
+
+ public void stop() {
+ builders.clear();
+ bindingBuilders.clear();
+ implementationBuilders.clear();
+ loaded = false;
+ }
+
+ public void addCompositeBuilder(CompositeBuilder builder) {
+ builders.put(builder.getID(), builder);
+ }
+
+ public void removeCompositeBuilder(CompositeBuilder builder) {
+ builders.remove(builder.getID());
+ }
+
+ public CompositeBuilder getCompositeBuilder(String id) {
+ loadBuilders();
+ return builders.get(id);
+ }
+
+ public void addContractBuilder(ContractBuilder contractBuilder){
+ this.contractBuilder = contractBuilder;
+ }
+
+ public void removeContractBuilder(ContractBuilder contractBuilder){
+ this.contractBuilder = null;
+ }
+
+ public ContractBuilder getContractBuilder(){
+ loadBuilders();
+ return contractBuilder;
+ }
+
+ /**
+ * Load builders declared under META-INF/services.
+ */
+ private synchronized void loadBuilders() {
+ if (loaded)
+ return;
+
+ FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
+
+ UtilityExtensionPoint utils = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utils.getUtility(InterfaceContractMapper.class);
+
+ // Get the provider factory service declarations
+ Collection<ServiceDeclaration> builderDeclarations;
+ ServiceDiscovery serviceDiscovery = registry.getServiceDiscovery();
+ try {
+ builderDeclarations = serviceDiscovery.getServiceDeclarations(CompositeBuilder.class.getName());
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ for (ServiceDeclaration builderDeclaration : builderDeclarations) {
+ Map<String, String> attributes = builderDeclaration.getAttributes();
+ String id = attributes.get("id");
+
+ 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.getBindingType(), 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.getImplementationType(), builder);
+ }
+
+ try {
+ builderDeclarations = serviceDiscovery.getServiceDeclarations(PolicyBuilder.class);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ for (ServiceDeclaration builderDeclaration : builderDeclarations) {
+ PolicyBuilder<?> builder = new LazyPolicyBuilder(builderDeclaration);
+ policyBuilders.put(builder.getPolicyType(), builder);
+ }
+
+ try {
+ builderDeclarations = serviceDiscovery.getServiceDeclarations(ContractBuilder.class);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ for (ServiceDeclaration builderDeclaration : builderDeclarations) {
+ contractBuilder = new LazyContractBuilder(builderDeclaration);
+ }
+
+
+ loaded = true;
+
+ }
+
+ public void addBindingBuilder(BindingBuilder<?> bindingBuilder) {
+ bindingBuilders.put(bindingBuilder.getBindingType(), bindingBuilder);
+ }
+
+ public <B extends Binding> BindingBuilder<B> getBindingBuilder(QName bindingType) {
+ loadBuilders();
+ return (BindingBuilder<B>)bindingBuilders.get(bindingType);
+ }
+
+ public <B extends Binding> void removeBindingBuilder(BindingBuilder<B> builder) {
+ bindingBuilders.remove(builder.getBindingType());
+ }
+
+ public void addImplementationBuilder(ImplementationBuilder<?> implementationBuilder) {
+ implementationBuilders.put(implementationBuilder.getImplementationType(), implementationBuilder);
+ }
+
+ public <I extends Implementation> ImplementationBuilder<I> getImplementationBuilder(QName implementationType) {
+ loadBuilders();
+ return (ImplementationBuilder<I>)implementationBuilders.get(implementationType);
+ }
+
+ public <I extends Implementation> void removeImplementationBuilder(ImplementationBuilder<I> builder) {
+ implementationBuilders.remove(builder.getImplementationType());
+ }
+
+ public void addPolicyBuilder(PolicyBuilder<?> policyBuilder) {
+ policyBuilders.put(policyBuilder.getPolicyType(), policyBuilder);
+ }
+
+ public <B> PolicyBuilder<B> getPolicyBuilder(QName policyType) {
+ loadBuilders();
+ return (PolicyBuilder<B>)policyBuilders.get(policyType);
+ }
+
+ public Collection<PolicyBuilder> getPolicyBuilders() {
+ loadBuilders();
+ return policyBuilders.values();
+ }
+
+ public <B> void removePolicyBuilder(PolicyBuilder<B> builder) {
+ policyBuilders.remove(builder.getPolicyType());
+ }
+
+ /**
+ * A wrapper around a composite builder allowing lazy
+ * loading and initialization of implementation providers.
+ */
+ private class LazyCompositeBuilder implements CompositeBuilder {
+
+ private FactoryExtensionPoint factories;
+ private InterfaceContractMapper mapper;
+ private String id;
+ private ServiceDeclaration builderDeclaration;
+ private CompositeBuilder builder;
+ private BuilderExtensionPoint builders;
+
+ private LazyCompositeBuilder(String id,
+ ServiceDeclaration factoryDeclaration,
+ BuilderExtensionPoint builders,
+ FactoryExtensionPoint factories,
+ InterfaceContractMapper mapper) {
+ this.id = id;
+ this.builderDeclaration = factoryDeclaration;
+ this.builders = builders;
+ this.factories = factories;
+ this.mapper = mapper;
+ }
+
+ public String getID() {
+ return id;
+ }
+
+ public Composite build(Composite composite, BuilderContext context)
+ throws CompositeBuilderException {
+ return getBuilder().build(composite, context);
+ }
+
+ private CompositeBuilder getBuilder() {
+ if (builder == null) {
+ try {
+ Class<CompositeBuilder> builderClass = (Class<CompositeBuilder>)builderDeclaration.loadClass();
+ try {
+ Constructor<CompositeBuilder> constructor =
+ builderClass.getConstructor(FactoryExtensionPoint.class, InterfaceContractMapper.class);
+ builder = constructor.newInstance(factories, mapper);
+ } catch (NoSuchMethodException e) {
+ try {
+ Constructor<CompositeBuilder> constructor =
+ builderClass.getConstructor(BuilderExtensionPoint.class,
+ FactoryExtensionPoint.class,
+ InterfaceContractMapper.class);
+ builder = constructor.newInstance(builders, factories, mapper);
+ } catch (NoSuchMethodException ex) {
+ Constructor<CompositeBuilder> constructor =
+ builderClass.getConstructor(ExtensionPointRegistry.class);
+ builder = constructor.newInstance(registry);
+ }
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return builder;
+ }
+
+ }
+
+ private class LazyBindingBuilder implements BindingBuilder {
+ private ServiceDeclaration sd;
+ private BindingBuilder<?> builder;
+ private QName qname;;
+
+ /**
+ * @param sd
+ */
+ public LazyBindingBuilder(ServiceDeclaration sd) {
+ super();
+ this.sd = sd;
+ this.qname = ServiceDeclarationParser.getQName(sd.getAttributes().get("qname"));
+ }
+
+ public void build(Component component, Contract contract, Binding binding, BuilderContext context, boolean rebuild) {
+ getBuilder().build(component, contract, binding, context, rebuild);
+ }
+
+ public QName getBindingType() {
+ return qname;
+ }
+
+
+ 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 ImplementationBuilder<?> builder;
+ private QName qname;;
+
+ /**
+ * @param sd
+ */
+ public LazyImplementationBuilder(ServiceDeclaration sd) {
+ super();
+ this.sd = sd;
+ this.qname = ServiceDeclarationParser.getQName(sd.getAttributes().get("qname"));
+ }
+
+ public void build(Component component, Implementation implementation, BuilderContext context) {
+ getBuilder().build(component, implementation, context);
+ }
+
+ public QName getImplementationType() {
+ return qname;
+ }
+
+ 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;
+ }
+
+ }
+
+ private class LazyPolicyBuilder implements PolicyBuilder {
+ private ServiceDeclaration sd;
+ private PolicyBuilder<?> builder;
+ private QName qname;;
+
+ /**
+ * @param sd
+ */
+ public LazyPolicyBuilder(ServiceDeclaration sd) {
+ super();
+ this.sd = sd;
+ this.qname = ServiceDeclarationParser.getQName(sd.getAttributes().get("qname"));
+ }
+
+ public boolean build(Component component, Implementation implementation, BuilderContext context) {
+ return getBuilder().build(component, implementation, context);
+ }
+
+ public QName getPolicyType() {
+ return qname;
+ }
+
+ public List<QName> getSupportedBindings() {
+ return getBuilder().getSupportedBindings();
+ }
+
+ private synchronized PolicyBuilder getBuilder() {
+ if (builder == null) {
+ try {
+ Class<?> builderClass = sd.loadClass();
+ try {
+ Constructor<?> constructor = builderClass.getConstructor(ExtensionPointRegistry.class);
+ builder = (PolicyBuilder)constructor.newInstance(registry);
+ } catch (NoSuchMethodException e) {
+ Constructor<?> constructor = builderClass.getConstructor();
+ builder = (PolicyBuilder)constructor.newInstance();
+
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return builder;
+ }
+
+ public boolean build(Endpoint endpoint, BuilderContext context) {
+ return getBuilder().build(endpoint, context);
+ }
+
+ public boolean build(org.apache.tuscany.sca.assembly.EndpointReference endpointReference, BuilderContext context) {
+ return getBuilder().build(endpointReference, context);
+ }
+
+ public boolean build(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context) {
+ return getBuilder().build(endpointReference, endpoint, context);
+ }
+ }
+
+ private class LazyContractBuilder implements ContractBuilder {
+ private ServiceDeclaration sd;
+ private ContractBuilder builder;
+
+ /**
+ * @param sd
+ */
+ public LazyContractBuilder(ServiceDeclaration sd) {
+ super();
+ this.sd = sd;
+ }
+
+/*
+ public boolean build(EndpointReference endpointReference, BuilderContext context){
+ return getBuilder().build(endpointReference, context);
+ }
+
+ public boolean build(Endpoint endpoint, BuilderContext context){
+ return getBuilder().build(endpoint, context);
+ }
+*/
+
+ public boolean build(InterfaceContract interfaceContract, BuilderContext context){
+ return getBuilder().build(interfaceContract, context);
+ }
+
+ private synchronized ContractBuilder getBuilder() {
+ if (builder == null) {
+ try {
+ Class<?> builderClass = sd.loadClass();
+ try {
+ Constructor<?> constructor = builderClass.getConstructor(ExtensionPointRegistry.class);
+ builder = (ContractBuilder)constructor.newInstance(registry);
+ } catch (NoSuchMethodException e) {
+ Constructor<?> constructor = builderClass.getConstructor();
+ builder = (ContractBuilder)constructor.newInstance();
+
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return builder;
+ }
+ }
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java
new file mode 100644
index 0000000000..d47c3d9032
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ImplementationBuilder.java
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Implementation;
+
+/**
+ * A builder that handles any build-time configuration needed by implementations.
+ *
+ * @version $Rev$ $Date$
+ * @tuscany.spi.extension.inheritfrom
+ */
+public interface ImplementationBuilder<I extends Implementation> {
+
+ /**
+ * Configure a component implementation.
+ *
+ * @param component The component
+ * @param context TODO
+ * @param contract The implementation
+ */
+ void build(Component component, I implmentation, BuilderContext context);
+
+ /**
+ * Get the QName of the implementation type
+ * @return
+ */
+ QName getImplementationType();
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Messages.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Messages.java
new file mode 100644
index 0000000000..4f2842c61a
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Messages.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * Constants for resource bundle names
+ */
+public interface Messages {
+ String RESOURCE_PACKAGE = "org.apache.tuscany.sca.assembly.builder.";
+ String ASSEMBLY_VALIDATION = RESOURCE_PACKAGE + "assembly-validation-messages";
+ String ASSEMBLY_CONFORMANCE = RESOURCE_PACKAGE + "assembly-conformance-messages";
+ String DEFINITIONS_VALIDATION = RESOURCE_PACKAGE + "definitions-validation-messages";
+ String BUILDER_VALIDATION_BUNDLE = "org.apache.tuscany.sca.builder.builder-validation-messages";
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java
new file mode 100644
index 0000000000..423c856973
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/PolicyBuilder.java
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.assembly.Implementation;
+
+/**
+ * A builder that is contributed by a specific policy language to validate the configurations
+ * for SCA endpoints, endpoint references and component implementations
+ * @tuscany.spi.extension.inheritfrom
+ */
+public interface PolicyBuilder<T> {
+ /**
+ * Get the policy type
+ * @return
+ */
+ QName getPolicyType();
+
+ /**
+ * Return the list of binding type QNames at which this policy implementation
+ * is targeted. Or null if the policy is not binding specific
+ * @return list of binding type QNames at which this policy implementation or null if it's not binding specific
+ */
+ List<QName> getSupportedBindings();
+
+ /**
+ * Build (and validate) the policy settings on the endpoint
+ * @param endpoint
+ * @param monitor
+ * @return true if the policy setting is compatible
+ */
+ boolean build(Endpoint endpoint, BuilderContext context);
+
+ /**
+ * Build (and validate) the policy settings on the endpoint reference
+ * @param endpointReference
+ * @param monitor
+ * @return true if the policy setting is compatible
+ */
+ boolean build(EndpointReference endpointReference, BuilderContext context);
+
+ /**
+ * Build (and validate) the policy settings on the component implementation
+ * @param component
+ * @param implementation
+ * @param monitor
+ * @return true if the policy setting is compatible
+ */
+ boolean build(Component component, Implementation implementation, BuilderContext context);
+
+ /**
+ * Build (and validate) the policy settings on the endpoint reference is compatible with the endpoint
+ * @param endpointReference
+ * @param endpoint
+ * @param context
+ * @return if the policy setting is compatible
+ */
+ boolean build(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context);
+
+}
diff --git a/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/WireBuilder.java b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/WireBuilder.java
new file mode 100644
index 0000000000..2bfbe85664
--- /dev/null
+++ b/sca-java-2.x/tags/2.0.1-RC1/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/WireBuilder.java
@@ -0,0 +1,39 @@
+/*
+ * 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;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+
+/**
+ * A builder that connects an endpoint reference to an endpoint
+ */
+public interface WireBuilder {
+ /**
+ * Build the endpoint reference against the endpoint. If the endpoint is a valid target for the
+ * endpoint reference, the wire buidler can populate some information from the endpoint into the
+ * endpoint reference (such as targetEndpoint, policySets or requiredIntents)
+ * @param endpointReference
+ * @param endpoint
+ * @param context
+ * @return true if the endpoint is a valid target for the endpoint reference
+ */
+ boolean build(EndpointReference endpointReference, Endpoint endpoint, BuilderContext context);
+}