diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-20 15:07:53 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-20 15:07:53 +0000 |
commit | b272cfd554a84b0537fe0de5dbfde41f8da3f688 (patch) | |
tree | fa6351e48c704693e605fcfc9e57bed57a9f5099 /java/sca | |
parent | fce6ad4c30b15b4284a94e7a00e084bf18748cf2 (diff) |
Remove the old Endpoint support. It has been replaced by Endpoint2/EndpointReference2. The old EndpointReference is still waiting to be removed.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@756512 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca')
36 files changed, 28 insertions, 3973 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java index 67c1ec1409..fa31657d0f 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java @@ -105,12 +105,5 @@ public interface ComponentReference extends Reference { * @param nonOverridable */ void setNonOverridable(boolean nonOverridable); - - /** - * Returns the endpoints implied by this reference. - * - * @return the endpoints implied by this reference - */ - List<Endpoint> getEndpoints(); - + } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java deleted file mode 100644 index 6b0c076ee5..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java +++ /dev/null @@ -1,32 +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; - - -import org.apache.tuscany.sca.assembly.impl.EndpointFactoryImpl; - -/** - * A default factory for the Endpoint model. - * - * @version $Rev$ $Date$ - */ -public class DefaultEndpointFactory extends EndpointFactoryImpl { - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java deleted file mode 100644 index ee63497fbe..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java +++ /dev/null @@ -1,167 +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; - -import java.util.List; - -import org.apache.tuscany.sca.interfacedef.InterfaceContract; - -/** - * Represents an endpoint (primarily a combination of a target service name and a set of - * candidate bindings) - * - * @version $Rev$ $Date$ - */ -public interface Endpoint extends Base, Cloneable { - - /** - * Get the name of the target service that this endpoint refers to - * - * @return target service name - */ - String getTargetName(); - - /** - * Set the name of the target service that this endpoint refers to - * - * @param targetName - */ - void setTargetName(String targetName); - - /** - * Get the source component model object - * - * @return source component - */ - Component getSourceComponent(); - - /** - * Set the source component model object - * - * @param component the source component for the endpoint - */ - void setSourceComponent(Component component); - - /** - * Get the source component reference model object - * - * @return reference the source component reference for the endpoint - */ - ComponentReference getSourceComponentReference(); - - /** - * Set the source component reference model object - * - * @param reference - */ - void setSourceComponentReference(ComponentReference reference); - - /** - * Get the resolved source binding - * - * @return binding the resolved source binding - */ - Binding getSourceBinding(); - - /** - * Set the resolved source binding - * - * @param binding the resolved source binding - */ - void setSourceBinding(Binding binding); - - /** - * Get the resolved source callback binding - * - * @return binding the resolved source callback binding - */ - Binding getSourceCallbackBinding(); - - /** - * Set the resolved source callback binding - * - * @param binding the resolved source callback binding - */ - void setSourceCallbackBinding(Binding binding); - - /** - * Get the list of candidate bindings that could be used to - * communication with the target service - * - * @return list of candidate bindings - */ - List<Binding> getCandidateBindings(); - - - /** - * Get the target component model object - * - * @return target component - */ - Component getTargetComponent(); - - /** - * Set the target component model object - * - * @param component target component - */ - void setTargetComponent(Component component); - - /** - * Get the target component service model object - * - * @return target component service - */ - ComponentService getTargetComponentService(); - - /** - * Set the target component service model object - * - * @param service - */ - void setTargetComponentService(ComponentService service); - - /** - * Get the resolved target binding - * - * @return target binding - */ - Binding getTargetBinding(); - - /** - * Set the resolved target binding - * - * @param binding target binding - */ - void setTargetBinding(Binding binding); - - /** - * Returns the interface contract defining the interface - * - * @return the interface contract - */ - InterfaceContract getInterfaceContract(); - - /** - * Sets the interface contract defining the interface - * - * @param interfaceContract the interface contract - */ - void setInterfaceContract(InterfaceContract interfaceContract); -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java deleted file mode 100644 index 93e6c4d630..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java +++ /dev/null @@ -1,37 +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; - - - -/** - * A factory for the endpoint model - * - * @version $Rev$ $Date$ - */ -public interface EndpointFactory { - - /** - * Create a new endpoint model object - * - * @return a new endpoint - */ - Endpoint createEndpoint(); - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java deleted file mode 100644 index 30b929c43c..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java +++ /dev/null @@ -1,33 +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; - -import org.apache.tuscany.sca.assembly.builder.impl.EndpointBuilderImpl; - -/** - * A default builder. - * - * @version $Rev$ $Date$ - */ -public class DefaultEndpointBuilder extends EndpointBuilderImpl { - public DefaultEndpointBuilder (){ - super(); - } -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java deleted file mode 100644 index e98be49551..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java +++ /dev/null @@ -1,42 +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; - -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A builder that handles the configuration of reference endpoints - * It collects together the logic so that it can be used at build time - * or later on during late binding scenarios - * - * @version $Rev$ $Date$ - */ -public interface EndpointBuilder { - - /** - * Build an endpoint. - * - * @param endpoint - * @param monitor - */ - void build(Endpoint endpoint, Monitor monitor); - -} 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 9a34c44eeb..eb06f67f8e 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 @@ -26,7 +26,6 @@ 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.CompositeReference; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; @@ -42,11 +41,9 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ComponentReferencePromotionBuilderImpl implements CompositeBuilder { private AssemblyFactory assemblyFactory; - private EndpointFactory endpointFactory; - public ComponentReferencePromotionBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory) { + public ComponentReferencePromotionBuilderImpl(AssemblyFactory assemblyFactory) { this.assemblyFactory = assemblyFactory; - this.endpointFactory = endpointFactory; } public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { @@ -94,7 +91,7 @@ public class ComponentReferencePromotionBuilderImpl implements CompositeBuilder ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference); for (ComponentReference promotedReference : promotedReferences) { ReferenceConfigurationUtil.reconcileReferenceBindings( - componentReference, promotedReference, assemblyFactory, endpointFactory, monitor); + componentReference, promotedReference, assemblyFactory, monitor); if (componentReference.getInterfaceContract() != null && // can be null in unit tests componentReference.getInterfaceContract().getCallbackInterface() != null) { SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java index 4698fa14e7..5552fda286 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java @@ -26,7 +26,6 @@ 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.CompositeReference; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; @@ -42,11 +41,9 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuilder { private AssemblyFactory assemblyFactory; - private EndpointFactory endpointFactory; - public ComponentReferencePromotionWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory) { + public ComponentReferencePromotionWireBuilderImpl(AssemblyFactory assemblyFactory) { this.assemblyFactory = assemblyFactory; - this.endpointFactory = endpointFactory; } public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { @@ -94,7 +91,7 @@ public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuil ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference); for (ComponentReference promotedReference : promotedReferences) { ReferenceConfigurationUtil.reconcileReferenceBindings( - componentReference, promotedReference, assemblyFactory, endpointFactory, monitor); + componentReference, promotedReference, assemblyFactory, monitor); if (componentReference.getInterfaceContract() != null && // can be null in unit tests componentReference.getInterfaceContract().getCallbackInterface() != null) { SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); 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 99d4defb21..fb2b34ac98 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 @@ -19,29 +19,21 @@ package org.apache.tuscany.sca.assembly.builder.impl; -import java.net.URI; -import java.util.ArrayList; 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; 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.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Multiplicity; 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.assembly.builder.DefaultEndpointBuilder; -import org.apache.tuscany.sca.assembly.builder.EndpointBuilder; import org.apache.tuscany.sca.definitions.Definitions; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.monitor.Monitor; @@ -52,14 +44,9 @@ import org.apache.tuscany.sca.monitor.Monitor; * @version $Rev$ $Date$ */ public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - - protected EndpointFactory endpointFactory; - private EndpointBuilder endpointBuilder; - - public ComponentReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper) { + + public ComponentReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper) { super(assemblyFactory, null, null, null, interfaceContractMapper); - this.endpointFactory = endpointFactory; - this.endpointBuilder = new DefaultEndpointBuilder(); } public String getID() { @@ -92,19 +79,9 @@ public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implement Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); - // Connect composite services and references to the component - // services and references that they promote - //connectCompositeServices(composite, components, componentServices); - //connectCompositeReferences(composite, componentReferences); - - // Compute the policies before connecting component references - //computePolicies(composite); - // Connect component references as described in wires connectWires(composite, componentServices, componentReferences, monitor); - // Connect component references to their targets -// connectComponentReferences(composite, components, componentServices, componentReferences, monitor); // Validate that references are wired or promoted, according // to their multiplicity @@ -207,466 +184,4 @@ public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implement composite.getWires().clear(); } - private List<Endpoint> createComponentReferenceTargets(Composite composite, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - ComponentReference componentReference, Monitor monitor) { - - List<Endpoint> endpoints = new ArrayList<Endpoint>(); - - if (componentReference.getAutowire() == Boolean.TRUE - && componentReference.getTargets().isEmpty()) { - - // Find suitable targets in the current composite for an - // autowired reference - Multiplicity multiplicity = componentReference.getMultiplicity(); - for (Component targetComponent : composite.getComponents()) { - // prevent autowire connecting to self - boolean skipSelf = false; - for (ComponentReference targetComponentReference : targetComponent - .getReferences()) { - if (componentReference == targetComponentReference) { - skipSelf = true; - } - } - - if (!skipSelf) { - for (ComponentService targetComponentService : targetComponent - .getServices()) { - if (componentReference.getInterfaceContract() == null - || interfaceContractMapper.isCompatible( - componentReference - .getInterfaceContract(), - targetComponentService - .getInterfaceContract())) { - - Endpoint endpoint = endpointFactory - .createEndpoint(); - endpoint.setTargetName(targetComponent.getName()); - endpoint.setSourceComponent(null); // TODO - fixed - // up at start - endpoint - .setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.setTargetComponent(targetComponent); - endpoint - .setTargetComponentService(targetComponentService); - endpoint.getCandidateBindings().addAll( - componentReference.getBindings()); - endpoints.add(endpoint); - - if (multiplicity == Multiplicity.ZERO_ONE - || multiplicity == Multiplicity.ONE_ONE) { - break; - } - } - } - } - } - - if (multiplicity == Multiplicity.ONE_N - || multiplicity == Multiplicity.ONE_ONE) { - if (endpoints.size() == 0) { - warning(monitor, "NoComponentReferenceTarget", - componentReference, componentReference.getName()); - } - } - - } else if (!componentReference.getTargets().isEmpty()) { - - // Check if the component reference does not mix the use of - // endpoints specified via - // binding elements with target endpoints specified via the target - // attribute - for (Binding binding : componentReference.getBindings()) { - if (binding.getURI() != null) { - warning(monitor, "ReferenceEndPointMixWithTarget", - composite, componentReference.getName()); - } - } - - // Resolve targets specified on the component reference - for (ComponentService componentService : componentReference - .getTargets()) { - - // Resolve the target component and service - String name = componentService.getName(); - ComponentService targetComponentService = componentServices - .get(name); - Component targetComponent; - int s = name.indexOf('/'); - if (s == -1) { - targetComponent = components.get(name); - } else { - targetComponent = components.get(name.substring(0, s)); - } - - if (targetComponentService != null) { - - // Check that the target component service provides - // a superset of the component reference interface - if (componentReference.getInterfaceContract() == null - || interfaceContractMapper.isCompatible( - componentReference.getInterfaceContract(), - targetComponentService - .getInterfaceContract())) { - - Endpoint endpoint = endpointFactory.createEndpoint(); - endpoint.setTargetName(targetComponent.getName()); - endpoint.setSourceComponent(null); // TODO - fixed up at - // start - endpoint - .setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.setTargetComponent(targetComponent); - endpoint - .setTargetComponentService(targetComponentService); - endpoint.getCandidateBindings().addAll( - componentReference.getBindings()); - endpoints.add(endpoint); - - // mark the reference target as resolved. Used later - // when we are looking to - // see if an sca binding is associated with a resolved - // target or not - componentService.setUnresolved(false); - } else { - warning(monitor, "ReferenceIncompatibleInterface", - composite, composite.getName().toString(), - componentReference.getName(), componentService - .getName()); - } - } else { - // add all the reference bindings into the target so that - // they - // can be used for comparison when the target is resolved at - // runtime - componentService.getBindings().addAll( - componentReference.getBindings()); - - Endpoint endpoint = endpointFactory.createEndpoint(); - endpoint.setTargetName(name); - endpoint.setSourceComponent(null); // TODO - fixed up at - // start - endpoint.setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.getCandidateBindings().addAll( - componentReference.getBindings()); - endpoints.add(endpoint); - - // The bindings will be cloned back into the reference when - // the - // target is finally resolved. - warning(monitor, "ComponentReferenceTargetNotFound", - composite, composite.getName().toString(), - componentService.getName()); - } - } - } else if ((componentReference.getReference() != null) - && (!componentReference.getReference().getTargets().isEmpty())) { - - // Resolve targets from the corresponding reference in the - // componentType - for (ComponentService componentService : componentReference - .getReference().getTargets()) { - - // Resolve the target component and service - String name = componentService.getName(); - ComponentService targetComponentService = componentServices - .get(name); - Component targetComponent; - int s = name.indexOf('/'); - if (s == -1) { - targetComponent = components.get(name); - } else { - targetComponent = components.get(name.substring(0, s)); - } - - if (targetComponentService != null) { - - // Check that the target component service provides - // a superset of - // the component reference interface - if (componentReference.getInterfaceContract() == null - || interfaceContractMapper.isCompatible( - componentReference.getInterfaceContract(), - targetComponentService - .getInterfaceContract())) { - - Endpoint endpoint = endpointFactory.createEndpoint(); - endpoint.setTargetName(targetComponent.getName()); - endpoint.setSourceComponent(null); // TODO - fixed up at - // start - endpoint - .setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.setTargetComponent(targetComponent); - endpoint - .setTargetComponentService(targetComponentService); - endpoint.getCandidateBindings().addAll( - componentReference.getBindings()); - endpoints.add(endpoint); - - // mark the reference target as resolved. Used later - // when we are looking to - // see if an sca binding is associated with a resolved - // target or not - componentService.setUnresolved(false); - } else { - warning(monitor, "ComponentIncompatibleInterface", - composite, componentReference.getName(), - componentService.getName()); - } - } else { - // add all the reference bindings into the target so that - // they - // can be used for comparison when the target is resolved at - // runtime - componentService.getBindings().addAll( - componentReference.getBindings()); - - // The bindings will be cloned back into the reference when - // the - // target is finally resolved. - - Endpoint endpoint = endpointFactory.createEndpoint(); - endpoint.setTargetName(name); - endpoint.setSourceComponent(null); // TODO - fixed up at - // start - endpoint.setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.getCandidateBindings().addAll( - componentReference.getBindings()); - endpoints.add(endpoint); - - warning(monitor, "ComponentReferenceTargetNotFound", - composite, composite.getName().toString(), - componentService.getName()); - } - } - } else if (componentReference.getAutowire() == Boolean.TRUE) { - - // Find suitable targets in the current composite for an - // autowired reference - Multiplicity multiplicity = componentReference.getMultiplicity(); - for (Component targetComponent : composite.getComponents()) { - // prevent autowire connecting to self - boolean skipSelf = false; - for (ComponentReference targetComponentReference : targetComponent - .getReferences()) { - if (componentReference == targetComponentReference) { - skipSelf = true; - } - } - - if (!skipSelf) { - for (ComponentService targetComponentService : targetComponent - .getServices()) { - if (componentReference.getInterfaceContract() == null - || interfaceContractMapper.isCompatible( - componentReference - .getInterfaceContract(), - targetComponentService - .getInterfaceContract())) { - - Endpoint endpoint = endpointFactory - .createEndpoint(); - endpoint.setTargetName(targetComponent.getName()); - endpoint.setSourceComponent(null); // TODO - fixed - // up at start - endpoint - .setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.setTargetComponent(targetComponent); - endpoint - .setTargetComponentService(targetComponentService); - endpoint.getCandidateBindings().addAll( - componentReference.getBindings()); - endpoints.add(endpoint); - - if (multiplicity == Multiplicity.ZERO_ONE - || multiplicity == Multiplicity.ONE_ONE) { - break; - } - } - } - } - } - - if (multiplicity == Multiplicity.ONE_N - || multiplicity == Multiplicity.ONE_ONE) { - if (endpoints.size() == 0) { - warning(monitor, "NoComponentReferenceTarget", - componentReference, componentReference.getName()); - } - } - } - - // if no endpoints have found so far retrieve any target names that are - // in binding URIs - if (endpoints.isEmpty()) { - for (Binding binding : componentReference.getBindings()) { - - String uri = binding.getURI(); - - // user hasn't put a uri on the binding so it's not a target - // name - if (uri == null) { - continue; - } - - // user might have put a local target name in the uri so get - // the path part and see if it refers to a target we know about - // - if it does the reference binding will be matched with a - // service binding - // - if it doesn't it is assumed to be an external reference - Component targetComponent = null; - ComponentService targetComponentService = null; - String path = null; - - try { - path = URI.create(uri).getPath(); - } catch (Exception ex) { - // just assume that no target is identified if - // a URI related exception is thrown - } - - if (path != null) { - if (path.startsWith("/")) { - path = path.substring(1); - } - - // Resolve the target component and service - targetComponentService = componentServices.get(path); - int s = path.indexOf('/'); - if (s == -1) { - targetComponent = components.get(path); - } else { - targetComponent = components.get(path.substring(0, s)); - } - } - - // if the path of the binding URI matches a component in the - // composite then configure an endpoint with this component as - // the target - // if not then the binding URI will be assumed to reference an - // external service - if (targetComponentService != null) { - - // Check that the target component service provides - // a superset of the component reference interface - if (componentReference.getInterfaceContract() == null - || interfaceContractMapper.isCompatible( - componentReference.getInterfaceContract(), - targetComponentService - .getInterfaceContract())) { - - Endpoint endpoint = endpointFactory.createEndpoint(); - endpoint.setTargetName(targetComponent.getName()); - endpoint.setSourceComponent(null); // TODO - fixed up at - // start - endpoint - .setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.setTargetComponent(targetComponent); - endpoint - .setTargetComponentService(targetComponentService); - endpoint.getCandidateBindings().add(binding); - endpoints.add(endpoint); - } else { - warning(monitor, "ReferenceIncompatibleInterface", - composite, composite.getName().toString(), - componentReference.getName(), uri); - } - } else { - - // create endpoints for manually configured bindings - Endpoint endpoint = endpointFactory.createEndpoint(); - endpoint.setTargetName(uri); - endpoint.setSourceComponent(null); // TODO - fixed up at - // start - endpoint.setSourceComponentReference(componentReference); - endpoint.setInterfaceContract(componentReference - .getInterfaceContract()); - endpoint.setSourceBinding(binding); - endpoints.add(endpoint); - } - } - } - - return endpoints; - } - - /** - * Connect references to their targets. - * - * @param composite - * @param componentServices - * @param componentReferences - * @param problems - */ - private void connectComponentReferences(Composite composite, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences, - Monitor monitor){ - - for (ComponentReference componentReference : componentReferences.values()) { - - List<Endpoint> endpoints = createComponentReferenceTargets(composite, - components, - componentServices, - componentReference, - monitor); - - componentReference.getEndpoints().addAll(endpoints); - - // the result of calculating the endpoints is either that bindings have been - // configured manually using a URI or that targets have been provided and the - // endpoint remains unresolved. So all endpoints should be either resved or uresolved. - boolean endpointsRequireAutomaticResolution = false; - for(Endpoint endpoint : endpoints){ - endpointsRequireAutomaticResolution = endpoint.isUnresolved(); - } - - // build each endpoint - if (endpointsRequireAutomaticResolution) { - - for(Endpoint endpoint : endpoints){ - endpointBuilder.build(endpoint, monitor); - } - - // TODO - The following step ensures that the reference binding list remains - // as the record of resolved targets for now. This needs fixing so - // that the endpoint takes on this responsibility. - componentReference.getBindings().clear(); - - if (componentReference.getCallback() != null){ - componentReference.getCallback().getBindings().clear(); - } - - for(Endpoint endpoint : endpoints){ - if (endpoint.isUnresolved() == false){ - componentReference.getBindings().add(endpoint.getSourceBinding()); - - if (componentReference.getCallback() != null){ - componentReference.getCallback().getBindings().add(endpoint.getSourceCallbackBinding()); - } - } - } - - } else { - // do nothing as no targets have been specified so the bindings - // in the reference binding list are assumed to be manually configured - } - } - } - } 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 6c8228d58a..bd904ede10 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 @@ -25,8 +25,6 @@ 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.DefaultEndpointFactory; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.SCABindingFactory; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; @@ -67,7 +65,6 @@ public class CompositeBuilderImpl implements CompositeBuilder { public CompositeBuilderImpl(FactoryExtensionPoint factories, InterfaceContractMapper mapper) { this(factories.getFactory(AssemblyFactory.class), - factories.getFactory(EndpointFactory.class), factories.getFactory(SCABindingFactory.class), factories.getFactory(PolicyFactory.class), factories.getFactory(DocumentBuilderFactory.class), @@ -75,26 +72,6 @@ public class CompositeBuilderImpl implements CompositeBuilder { 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, - EndpointFactory endpointFactory, - SCABindingFactory scaBindingFactory, - PolicyFactory intentAttachPointTypeFactory, - InterfaceContractMapper interfaceContractMapper) { - this(assemblyFactory, endpointFactory, scaBindingFactory, intentAttachPointTypeFactory, - null, null, interfaceContractMapper); - } /** * Constructs a new composite builder. @@ -112,31 +89,10 @@ public class CompositeBuilderImpl implements CompositeBuilder { SCABindingFactory scaBindingFactory, PolicyFactory intentAttachPointTypeFactory, InterfaceContractMapper interfaceContractMapper) { - this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, + this(assemblyFactory, scaBindingFactory, intentAttachPointTypeFactory, null, null, interfaceContractMapper); } - - /** - * Constructs a new composite builder. - * - * @param assemblyFactory - * @param scaBindingFactory - * @param intentAttachPointTypeFactory - * @param documentBuilderFactory - * @param transformerFactory - * @param interfaceContractMapper - * @param monitor - */ - public CompositeBuilderImpl(AssemblyFactory assemblyFactory, - SCABindingFactory scaBindingFactory, - PolicyFactory intentAttachPointTypeFactory, - DocumentBuilderFactory documentBuilderFactory, - TransformerFactory transformerFactory, - InterfaceContractMapper interfaceContractMapper) { - this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory, - documentBuilderFactory, transformerFactory, interfaceContractMapper); - } - + /** * Constructs a new composite builder. * @@ -149,21 +105,17 @@ public class CompositeBuilderImpl implements CompositeBuilder { * @param monitor */ public CompositeBuilderImpl(AssemblyFactory assemblyFactory, - EndpointFactory endpointFactory, SCABindingFactory scaBindingFactory, PolicyFactory intentAttachPointTypeFactory, DocumentBuilderFactory documentBuilderFactory, TransformerFactory transformerFactory, InterfaceContractMapper interfaceContractMapper) { - - if (endpointFactory == null){ - endpointFactory = new DefaultEndpointFactory(); - } + compositeIncludeBuilder = new CompositeIncludeBuilderImpl(); - componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper); + componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, interfaceContractMapper); //componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, endpointFactory); - componentReferencePromotionBuilder = new ComponentReferencePromotionBuilderImpl(assemblyFactory, endpointFactory); + componentReferencePromotionBuilder = new ComponentReferencePromotionBuilderImpl(assemblyFactory); //compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory); compositeCloneBuilder = new CompositeCloneBuilderImpl(); componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper); @@ -172,8 +124,8 @@ public class CompositeBuilderImpl implements CompositeBuilder { compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper); //componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory); //compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory); - compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper); - compositePolicyBuilder = new CompositePolicyBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper); + compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, interfaceContractMapper); + compositePolicyBuilder = new CompositePolicyBuilderImpl(assemblyFactory, interfaceContractMapper); componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(); componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(); 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 28ca856c0f..1fc00705e7 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 @@ -31,7 +31,6 @@ import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeReference; import org.apache.tuscany.sca.assembly.CompositeService; import org.apache.tuscany.sca.assembly.Endpoint2; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; @@ -54,7 +53,6 @@ import org.apache.tuscany.sca.policy.PolicySubject; public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { public CompositePolicyBuilderImpl(AssemblyFactory assemblyFactory, - EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper) { super(assemblyFactory, null, null, null, interfaceContractMapper); } 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 abacc06067..eb858b4e3d 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 @@ -31,7 +31,6 @@ 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.CompositeService; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; @@ -50,7 +49,7 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class CompositePromotionBuilderImpl extends BaseBuilderImpl implements CompositeBuilder { - public CompositePromotionBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper) { + public CompositePromotionBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper) { super(assemblyFactory, null, null, null, interfaceContractMapper); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java index 3786cdfa38..451b378941 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java @@ -25,7 +25,6 @@ import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.Composite; import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; @@ -40,11 +39,9 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class CompositeReferenceWireBuilderImpl implements CompositeBuilder { private AssemblyFactory assemblyFactory; - private EndpointFactory endpointFactory; - public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory) { + public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory) { this.assemblyFactory = assemblyFactory; - this.endpointFactory = endpointFactory; } public String getID() { @@ -72,7 +69,7 @@ public class CompositeReferenceWireBuilderImpl implements CompositeBuilder { ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference); for (ComponentReference promotedReference : promotedReferences) { ReferenceConfigurationUtil.reconcileReferenceBindings( - compositeReference, promotedReference, assemblyFactory, endpointFactory, monitor); + compositeReference, promotedReference, assemblyFactory, monitor); if (compositeReference.getInterfaceContract() != null && // can be null in unit tests compositeReference.getInterfaceContract().getCallbackInterface() != null) { SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java deleted file mode 100644 index aaface154b..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java +++ /dev/null @@ -1,209 +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.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.OptimizableBinding; -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.builder.EndpointBuilder; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySubject; - -/** - * A factory for the Endpoint model. - * - * @version $Rev$ $Date$ - */ -public abstract class EndpointBuilderImpl implements EndpointBuilder { - - public EndpointBuilderImpl (){ - } - - private void warning(Monitor monitor, String message, Object model, String... messageParameters) { - if (monitor != null){ - Problem problem = monitor.createProblem(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } - - private void error(Monitor monitor, String message, Object model, Exception ex) { - if (monitor != null){ - Problem problem = null; - problem = monitor.createProblem(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } - } - - /** - * Resolve an endpoint against the provided target information and the - * set of candidate bindings. - */ - public void build(Endpoint endpoint, Monitor monitor) { - - // If this endpoint is not fully configured then don't try and resolve it - if (endpoint.getTargetComponentService() == null){ - return; - } - - // Does the reference expect callbacks - boolean bidirectional = false; - - if (endpoint.getSourceComponentReference().getInterfaceContract() != null && - endpoint.getSourceComponentReference().getInterfaceContract().getCallbackInterface() != null) { - bidirectional = true; - } - - // if the target service is a promoted service then find the - // service it promotes - if (endpoint.getTargetComponentService().getService() instanceof CompositeService) { - CompositeService compositeService = (CompositeService) endpoint.getTargetComponentService().getService(); - // Find the promoted component service - ComponentService promotedComponentService = ServiceConfigurationUtil.getPromotedComponentService(compositeService); - if (promotedComponentService != null && !promotedComponentService.isUnresolved()) { - endpoint.setTargetComponentService(promotedComponentService); - } - } - - try { - PolicyConfigurationUtil.determineApplicableBindingPolicySets(endpoint.getSourceComponentReference(), - endpoint.getTargetComponentService()); - } catch ( Exception e ) { - error(monitor, "PolicyRelatedException", endpoint, e); - } - - - // Match the binding against the bindings of the target service - Binding resolvedBinding = matchBinding(endpoint.getTargetComponent(), - endpoint.getTargetComponentService(), - endpoint.getCandidateBindings(), - endpoint.getTargetComponentService().getBindings()); - if (resolvedBinding == null) { - warning(monitor, "NoMatchingBinding", - endpoint.getSourceComponentReference(), - endpoint.getSourceComponentReference().getName(), - endpoint.getTargetComponentService().getName()); - } else { - endpoint.setSourceBinding(resolvedBinding); - } - - if (bidirectional) { - Binding resolvedCallbackBinding = matchBinding(endpoint.getTargetComponent(), - endpoint.getTargetComponentService(), - endpoint.getSourceComponentReference().getCallback().getBindings(), - endpoint.getTargetComponentService().getCallback().getBindings()); - if (resolvedBinding == null) { - warning(monitor, "NoMatchingCallbackBinding", - endpoint.getSourceComponentReference(), - endpoint.getSourceComponentReference().getName(), - endpoint.getTargetComponentService().getName()); - } else { - endpoint.setSourceCallbackBinding(resolvedCallbackBinding); - } - } - } - - private boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) { - boolean isCompatible = true; - if ( refBinding instanceof PolicySubject && svcBinding instanceof PolicySubject ) { - //TODO : need to add more compatibility checks at the policy attachment levels - for ( PolicySet svcPolicySet : ((PolicySubject)svcBinding).getPolicySets() ) { - isCompatible = false; - for ( PolicySet refPolicySet : ((PolicySubject)refBinding).getPolicySets() ) { - if ( svcPolicySet.equals(refPolicySet) ) { - isCompatible = true; - break; - } - } - //if there exists no matching policy set in the reference binding - if ( !isCompatible ) { - return isCompatible; - } - } - } - return isCompatible; - } - - - private Binding matchBinding(Component targetComponent, ComponentService targetComponentService, List<Binding> source, List<Binding> target) { - List<Binding> matched = new ArrayList<Binding>(); - // Find the corresponding bindings from the service side - for (Binding binding : source) { - for (Binding serviceBinding : target) { - if (binding.getClass() == serviceBinding.getClass() && - hasCompatiblePolicySets(binding, serviceBinding)) { - - try { - Binding cloned = (Binding)binding.clone(); - - //Customise the binding name to make it unique - // regardless of how many bindings or targets there are - if ( targetComponent != null){ - cloned.setName(binding.getName()); - } else { - cloned.setName(binding.getName()); - } - - // Set the binding URI to the URI of the target service - // that has been matched - if (binding.getURI() == null) { - cloned.setURI(serviceBinding.getURI()); - } - - if (binding instanceof OptimizableBinding) { - OptimizableBinding endpoint = ((OptimizableBinding)cloned); - endpoint.setTargetComponent(targetComponent); - endpoint.setTargetComponentService(targetComponentService); - endpoint.setTargetBinding(serviceBinding); - } - - matched.add(cloned); - break; - } catch (Exception ex) { - // do nothing - } - } - } - } - if (matched.isEmpty()) { - // No matching binding - return null; - } else { - for (Binding binding : matched) { - // If binding.sca is present, use it - if (SCABinding.class.isInstance(binding)) { - return binding; - } - } - // Use the first one - return matched.get(0); - } - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java deleted file mode 100644 index 3120f16334..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReference2BuilderImpl.java +++ /dev/null @@ -1,308 +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.impl; - -import java.util.ArrayList; -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; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Endpoint2; -import org.apache.tuscany.sca.assembly.EndpointReference2; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.OptimizableBinding; -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.definitions.Definitions; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySubject; - -/** - * An builder that takes endpoint references and resolves them. It either finds local - * service endpoints if they are available or asks the domain. The main function here - * is to perform binding and policy matching. - * This is a separate builder in case it is required by undresolved endpoints - * once the runtime has started. - * - * @version $Rev$ $Date$ - */ -public class EndpointReference2BuilderImpl extends BaseBuilderImpl implements CompositeBuilder/*, EndpointReference2Builder*/ { - - - public EndpointReference2BuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper) { - super(assemblyFactory, null, null, null, interfaceContractMapper); - } - - public String getID() { - return "org.apache.tuscany.sca.assembly.builder.EndpointReference2Builder"; - } - - /** - * Build all the endpoint references - * - * @param composite - */ - public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException - { - // process top level composite references - // TODO - I don't think OASIS allows for these - // - //processCompositeReferences(composite); - - // process component services - processComponentReferences(composite, monitor); - } - - private void processCompositeReferences(Composite composite) { - // TODO do we need this for OASIS? - } - - private void processComponentReferences(Composite composite, Monitor monitor) { - - // index all of the components in the composite - Map<String, Component> components = new HashMap<String, Component>(); - indexComponents(composite, components); - - // index all of the services in the composite - Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); - indexServices(composite, componentServices); - - // create endpoint references for each component's references - for (Component component : composite.getComponents()) { - // recurse for composite implementations - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - processComponentReferences((Composite)implementation, monitor); - } - - // build endpoint references - for (ComponentReference reference : component.getReferences()) { - for (EndpointReference2 endpointReference : reference.getEndpointReferences()){ - build(endpointReference, monitor); - } - } - } - } - - /** - * Build a single endpoint reference - * - * @param endpoint - * @param monitor - */ - public void build(EndpointReference2 endpointReference, Monitor monitor) { - Endpoint2 endpoint = endpointReference.getTargetEndpoint(); - - if (endpoint == null){ - // an error? - } else { - if (endpoint.isUnresolved() == false){ - // everything is resolved - return; - } - - if (endpointReference.isUnresolved() == false ){ - // TODO - bring resolution and binding matching together - // just do binding matching - matchForwardBinding(endpointReference, - endpointReference.getTargetEndpoint().getService(), - monitor); - - matchCallbackBinding(endpointReference, - endpointReference.getTargetEndpoint().getService(), - monitor); - } else { - // resolve the endpoint reference in the domain and then - // match bindings - } - } - } - - // TODO - In OASIS case there are no bindings to match with on the - // reference side. This code will be factored out into a pluggable - // piece - private void matchForwardBinding(EndpointReference2 endpointReference, - ComponentService service, - Monitor monitor) { - - List<Binding> matchedReferenceBinding = new ArrayList<Binding>(); - List<Endpoint2> matchedServiceEndpoint = new ArrayList<Endpoint2>(); - - // Find the corresponding bindings from the service side - for (Binding referenceBinding : endpointReference.getReference().getBindings()) { - for (Endpoint2 serviceEndpoint : service.getEndpoints()) { - - if (referenceBinding.getClass() == serviceEndpoint.getBinding().getClass() && - hasCompatiblePolicySets(referenceBinding, serviceEndpoint.getBinding())) { - - matchedReferenceBinding.add(referenceBinding); - matchedServiceEndpoint.add(serviceEndpoint); - } - } - } - - if (matchedReferenceBinding.isEmpty()) { - // No matching binding - endpointReference.setBinding(null); - endpointReference.setTargetEndpoint(null); - warning(monitor, - "NoMatchingBinding", - endpointReference.getReference(), - endpointReference.getReference().getName(), - service.getName()); - return; - } else { - // default to using the first matched binding - int selectedBinding = 0; - - for (int i = 0; i < matchedReferenceBinding.size(); i++) { - // If binding.sca is present, use it - if (SCABinding.class.isInstance(matchedReferenceBinding.get(i))) { - selectedBinding = i; - } - } - - Binding referenceBinding = matchedReferenceBinding.get(selectedBinding); - Endpoint2 serviceEndpoint = matchedServiceEndpoint.get(selectedBinding); - - // populate the endpoint reference - try { - - Binding cloned = (Binding) referenceBinding.clone(); - - // Set the binding URI to the URI of the target service - // that has been matched - if (referenceBinding.getURI() == null) { - cloned.setURI(serviceEndpoint.getBinding().getURI()); - } - - // TODO - can we remove this? - if (cloned instanceof OptimizableBinding) { - OptimizableBinding optimizableBinding = (OptimizableBinding)cloned; - optimizableBinding.setTargetComponent(serviceEndpoint.getComponent()); - optimizableBinding.setTargetComponentService(serviceEndpoint.getService()); - optimizableBinding.setTargetBinding(serviceEndpoint.getBinding()); - } - - endpointReference.setBinding(referenceBinding); - endpointReference.setTargetEndpoint(serviceEndpoint); - - } catch (Exception ex) { - // do nothing - } - } - } - - // TODO - // Pretty much a duplicate of matchForwardBinding to handle callback bindings - // will rationalize when I understand what we need to do with callbacks - private void matchCallbackBinding(EndpointReference2 endpointReference, - ComponentService service, - Monitor monitor) { - - // if no callback on the interface do nothing - if (endpointReference.getReference().getInterfaceContract() == null || - endpointReference.getReference().getInterfaceContract().getCallbackInterface() == null){ - return; - } - - List<Binding> matchedReferenceBinding = new ArrayList<Binding>(); - List<Binding> matchedServiceBinding = new ArrayList<Binding>(); - - // Find the corresponding bindings from the service side - for (Binding referenceBinding : endpointReference.getReference().getCallback().getBindings()) { - for (Binding serviceBinding : service.getCallback().getBindings()) { - - if (referenceBinding.getClass() == serviceBinding.getClass() && - hasCompatiblePolicySets(referenceBinding, serviceBinding)) { - - matchedReferenceBinding.add(referenceBinding); - matchedServiceBinding.add(serviceBinding); - } - } - } - - if (matchedReferenceBinding.isEmpty()) { - // No matching binding - endpointReference.setCallbackEndpoint(null); - warning(monitor, - "NoMatchingCallbackBinding", - endpointReference.getReference(), - endpointReference.getReference().getName(), - service.getName()); - return; - } else { - // default to using the first matched binding - int selectedBinding = 0; - - for (int i = 0; i < matchedReferenceBinding.size(); i++){ - // If binding.sca is present, use it - if (SCABinding.class.isInstance(matchedReferenceBinding.get(i))) { - selectedBinding = i; - } - } - - Binding selectedCallbackBinding = matchedReferenceBinding.get(selectedBinding); - - ComponentService callbackService = endpointReference.getReference().getCallbackService(); - - if (callbackService != null) { - // find the callback endpoint that has the selected binding - for (Endpoint2 endpoint : callbackService.getEndpoints()){ - if (endpoint.getBinding().getName().startsWith(selectedCallbackBinding.getName())){ - endpointReference.setCallbackEndpoint(endpoint); - break; - } - } - } - } - } - - private boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) { - boolean isCompatible = true; - if ( refBinding instanceof PolicySubject && svcBinding instanceof PolicySubject ) { - //TODO : need to add more compatibility checks at the policy attachment levels - for ( PolicySet svcPolicySet : ((PolicySubject)svcBinding).getPolicySets() ) { - isCompatible = false; - for ( PolicySet refPolicySet : ((PolicySubject)refBinding).getPolicySets() ) { - if ( svcPolicySet.equals(refPolicySet) ) { - isCompatible = true; - break; - } - } - //if there exists no matching policy set in the reference binding - if ( !isCompatible ) { - return isCompatible; - } - } - } - return isCompatible; - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java index 33611fb8c0..c1862e0380 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java @@ -27,7 +27,6 @@ import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.EndpointFactory; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.OptimizableBinding; import org.apache.tuscany.sca.assembly.Reference; @@ -167,7 +166,6 @@ abstract class ReferenceConfigurationUtil { static void reconcileReferenceBindings(Reference reference, ComponentReference promotedReference, AssemblyFactory assemblyFactory, - EndpointFactory endpointFactory, Monitor monitor) { if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java index 9a90d7aaea..2380bbf088 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java @@ -26,7 +26,6 @@ import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.interfacedef.InterfaceContract; @@ -41,7 +40,6 @@ public class ComponentReferenceImpl extends ReferenceImpl implements ComponentRe private boolean nonOverridable; private List<CompositeReference> promotedAs = new ArrayList<CompositeReference>(); private ComponentService callbackService; - private List<Endpoint> endpoints = new ArrayList<Endpoint>(); /** * Constructs a new component reference. @@ -88,9 +86,6 @@ public class ComponentReferenceImpl extends ReferenceImpl implements ComponentRe this.callbackService = callbackService; } - public List<Endpoint> getEndpoints(){ - return endpoints; - } /** * Use endpoint information to work out what the interface contract for the @@ -100,12 +95,6 @@ public class ComponentReferenceImpl extends ReferenceImpl implements ComponentRe public InterfaceContract getInterfaceContract(Binding binding){ InterfaceContract interfaceContract = null; - for (Endpoint theEndpoint : endpoints){ - if (theEndpoint.getSourceBinding() == binding){ - interfaceContract = theEndpoint.getInterfaceContract(); - } - } - if (interfaceContract == null){ interfaceContract = getInterfaceContract(); } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java deleted file mode 100644 index ece51cbe9b..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java +++ /dev/null @@ -1,41 +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.impl; - - -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointFactory; - -/** - * A factory for the Endpoint model. - * - * @version $Rev$ $Date$ - */ -public abstract class EndpointFactoryImpl implements EndpointFactory { - - public EndpointFactoryImpl (){ - - } - - public Endpoint createEndpoint() { - return new EndpointImpl(); - } - -} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java deleted file mode 100644 index 5748abb07d..0000000000 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java +++ /dev/null @@ -1,154 +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.impl; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; - -/** - * The assembly model object for an endpoint. - * - * @version $Rev$ $Date$ - */ -public class EndpointImpl implements Endpoint { - - private String targetName; - - private Component sourceComponent; - private ComponentReference sourceComponentReference; - private Binding resolvedBinding; - private Binding resolvedCallbackBinding; - - private List<Binding> candidateBindings = new ArrayList<Binding>(); - - private Component targetComponent; - private ComponentService targetComponentService; - private Binding targetBinding; - private Binding targetCallbackBinding; - - private InterfaceContract interfaceContract; - - protected EndpointImpl() { - } - - public boolean isUnresolved() { - return resolvedBinding == null; - } - - public void setUnresolved(boolean unresolved) { - // do nothing as the status is determined by having - // a resolved source binding - } - - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - public String getTargetName(){ - return targetName; - } - - public void setTargetName(String targetName){ - this.targetName = targetName; - } - - public Component getSourceComponent() { - return sourceComponent; - } - - public void setSourceComponent(Component sourceComponent) { - this.sourceComponent = sourceComponent; - } - - public ComponentReference getSourceComponentReference() { - return sourceComponentReference; - } - - public void setSourceComponentReference(ComponentReference sourceComponentReference) { - this.sourceComponentReference = sourceComponentReference; - } - - public Binding getSourceBinding() { - return resolvedBinding; - } - - public void setSourceBinding(Binding resolvedBinding) { - this.resolvedBinding = resolvedBinding; - } - - public Binding getSourceCallbackBinding(){ - return resolvedCallbackBinding; - } - - public void setSourceCallbackBinding(Binding resolvedCallbackBinding){ - this.resolvedCallbackBinding = resolvedCallbackBinding; - } - - public List<Binding> getCandidateBindings() { - return candidateBindings; - } - - public Component getTargetComponent() { - return targetComponent; - } - - public void setTargetComponent(Component targetComponent) { - this.targetComponent = targetComponent; - } - - public ComponentService getTargetComponentService() { - return targetComponentService; - } - - public void setTargetComponentService(ComponentService targetComponentService) { - this.targetComponentService = targetComponentService; - } - - public Binding getTargetBinding() { - return targetBinding; - } - - public void setTargetBinding(Binding targetBinding) { - this.targetBinding = targetBinding; - } - - public Binding getTargetCallbackBinding(){ - return targetCallbackBinding; - } - - public void setTargetCallbackBinding(Binding targetCallbackBinding){ - this.targetCallbackBinding = targetCallbackBinding; - } - - public InterfaceContract getInterfaceContract() { - return interfaceContract; - } - - public void setInterfaceContract(InterfaceContract interfaceContract) { - this.interfaceContract = interfaceContract; - } -} diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java deleted file mode 100644 index b2d0639a16..0000000000 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java +++ /dev/null @@ -1,180 +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.endpointresolver; - -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; - -/** - * Default implementation of a provider factory extension point. - * - * @version $Rev$ $Date$ - */ -public class DefaultEndpointResolverFactoryExtensionPoint implements EndpointResolverFactoryExtensionPoint { - - private ExtensionPointRegistry registry; - private final Map<Class<?>, EndpointResolverFactory> endpointResolverFactories = new HashMap<Class<?>, EndpointResolverFactory>(); - private boolean loaded; - - /** - * The default constructor. Does nothing. - * - */ - public DefaultEndpointResolverFactoryExtensionPoint(ExtensionPointRegistry registry) { - this.registry = registry; - } - - /** - * Add an endpoint resolver factory. - * - * @param endpointResolverFactory The resolver factory - */ - public void addEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory){ - endpointResolverFactories.put(endpointResolverFactory.getModelType(), endpointResolverFactory); - } - - /** - * Remove a endpoint resolver factory. - * - * @param endpointResolverFactory The endpoint resolver factory - */ - public void removeEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory){ - endpointResolverFactories.remove(endpointResolverFactory.getModelType()); - } - - /** - * Returns the provider factory associated with the given model type. - * @param modelType A model type - * @return The provider factory associated with the given model type - */ - public EndpointResolverFactory getEndpointResolverFactory(Class<?> modelType) { - loadProviderFactories(); - - Class<?>[] classes = modelType.getInterfaces(); - for (Class<?> c : classes) { - EndpointResolverFactory factory = endpointResolverFactories.get(c); - if (factory != null) { - return factory; - } - } - return endpointResolverFactories.get(modelType); - } - - - /** - * Load provider factories declared under META-INF/services. - * @param registry - */ - private synchronized void loadProviderFactories() { - if (loaded) - return; - - // Get the provider factory service declarations - Set<ServiceDeclaration> factoryDeclarations; - ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance(); - try { - factoryDeclarations = serviceDiscovery.getServiceDeclarations(EndpointResolverFactory.class.getName()); - } catch (Exception e) { - throw new IllegalStateException(e); - } - - // Get the extension point - EndpointResolverFactoryExtensionPoint factoryExtensionPoint = - registry.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); - List<EndpointResolverFactory> factories = new ArrayList<EndpointResolverFactory>(); - - for (ServiceDeclaration factoryDeclaration : factoryDeclarations) { - Map<String, String> attributes = factoryDeclaration.getAttributes(); - - // Find the model type that identifies this resolver - String modelTypeName = attributes.get("model"); - - // Create a provider factory wrapper and register it - EndpointResolverFactory factory = - new LazyEndpointResolverFactory(registry, modelTypeName, factoryDeclaration); - factoryExtensionPoint.addEndpointResolverFactory(factory); - factories.add(factory); - } - - loaded = true; - } - - /** - * A wrapper around an endpoint provider factory allowing lazy - * loading and initialization of endpoint providers. - */ - private class LazyEndpointResolverFactory implements EndpointResolverFactory { - private ExtensionPointRegistry registry; - private String modelTypeName; - private ServiceDeclaration providerClass; - private EndpointResolverFactory factory; - private Class<?> modelType; - - private LazyEndpointResolverFactory(ExtensionPointRegistry registry, - String modelTypeName, - ServiceDeclaration providerClass) { - this.registry = registry; - this.modelTypeName = modelTypeName; - this.providerClass = providerClass; - } - - @SuppressWarnings("unchecked") - private EndpointResolverFactory getFactory() { - if (factory == null) { - try { - Class<EndpointResolverFactory> factoryClass = (Class<EndpointResolverFactory>)providerClass.loadClass(); - Constructor<EndpointResolverFactory> constructor = - factoryClass.getConstructor(ExtensionPointRegistry.class); - factory = constructor.newInstance(registry); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - return factory; - } - - public EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding) { - return getFactory().createEndpointResolver(endpoint, binding); - } - - public Class<?> getModelType() { - if (modelType == null) { - try { - modelType = providerClass.loadClass(modelTypeName); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - return modelType; - } - - } - -} diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java deleted file mode 100644 index 79a10f6d84..0000000000 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java +++ /dev/null @@ -1,55 +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.endpointresolver; - - -/** - * A reference binding implementation can options implement this - * interface to tie into the Tuscany SCA runtime - * - * @version $Rev$ $Date$ - */ -public interface EndpointResolver { - - /** - * This method will be invoked when the endpoint is - * activated. It gives the resolver the opportunity - * to do any set up ready for when it is asked to - * resolve the endpoint when a message arrives - */ - void start(); - - /** - * This method will be invoked when the endpoint is - * to be resolved. The resolver will attempt to resolve the - * endpoint against available services. The resolvers extending - * this interface will provide environment or binding specific - * resolution processing - */ - void resolve(); - - /** - * This method will be invoked when the endpont is - * deactivated. It gives the resolver the opportunity - * to take and required resolver shutdown actions - */ - void stop(); - -} diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java deleted file mode 100644 index fdd304a9c7..0000000000 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java +++ /dev/null @@ -1,44 +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.endpointresolver; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Endpoint; - -/** - * A factory for creating the runtime artifacts that resolve endpoints. - * - * @version $Rev$ $Date$ - */ -public interface EndpointResolverFactory <M>{ - - /** - * Creates a new endpoint resolver for the given component, - * reference and binding. - * - * @param component The runtime component - * @param reference The reference on the runtime component - * @param enpoint The endpoint assembly model object - * @return The endpoint provider - */ - EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding); - - Class<M> getModelType(); -} diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java deleted file mode 100644 index 9d5c2e950b..0000000000 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java +++ /dev/null @@ -1,56 +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.endpointresolver; - - - -/** - * An extension point for resolver factories. Holds all of the resolver - * factories from loaded extension points. Allows a resolver factory - * to be located based on a given model type. Hence the runtime can - * generate endpoint resolvers from the in memory assembly model. - * - * @version $Rev$ $Date$ - */ -public interface EndpointResolverFactoryExtensionPoint { - - - /** - * Add an endpoint resolver factory. - * - * @param endpointResolverFactory The resolver factory - */ - void addEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory); - - /** - * Remove a endpoint resolver factory. - * - * @param endpointResolverFactory The endpoint resolver factory - */ - void removeEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory); - - /** - * Returns the endpoint resolver factory associated with the given binding type. - * @param bindingType A binding type - * @return The endpoint resolver factory associated with the given binding type - */ - EndpointResolverFactory getEndpointResolverFactory(Class<?> bindingType); - -} diff --git a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java index 84e2f4588b..a2a6f03b08 100644 --- a/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java +++ b/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java @@ -23,9 +23,7 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference2; -import org.apache.tuscany.sca.endpointresolver.EndpointResolver; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.provider.PolicyProvider; @@ -78,24 +76,7 @@ public interface RuntimeComponentReference extends ComponentReference { * @param bindingProvider The runtime reference binding provider */ void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider); - - /** - * Returns the endpoint resolver associated with this - * component reference and the given endpoint. - * - * @param endpont The assembly model endpoint - * @return The enpoint resolver - */ - EndpointResolver getEndpointResolver(Endpoint endpoint); - - /** - * Sets the endpoint resolver associated with this - * component reference and the given endpoint. - * - * @param binding The assembly model binding - * @param bindingProvider The runtime reference binding provider - */ - void setEndpointResolver(Endpoint endpoint, EndpointResolver endpointResolver); + /** * Add a policy provider for the given binding to the reference diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java deleted file mode 100644 index 67edf3ab9d..0000000000 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java +++ /dev/null @@ -1,1072 +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.core.assembly.impl; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -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; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.OptimizableBinding; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.context.ComponentContextFactory; -import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint; -import org.apache.tuscany.sca.context.PropertyValueFactory; -import org.apache.tuscany.sca.context.RequestContextFactory; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.core.assembly.ActivationException; -import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.core.context.CompositeContext; -import org.apache.tuscany.sca.core.context.impl.CompositeContextImpl; -import org.apache.tuscany.sca.core.conversation.ConversationManager; -import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor; -import org.apache.tuscany.sca.core.invocation.ProxyFactory; -import org.apache.tuscany.sca.core.scope.Scope; -import org.apache.tuscany.sca.core.scope.ScopeContainer; -import org.apache.tuscany.sca.core.scope.ScopeRegistry; -import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent; -import org.apache.tuscany.sca.core.scope.impl.ConversationalScopeContainer; -import org.apache.tuscany.sca.endpointresolver.EndpointResolver; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.provider.BindingProviderFactory; -import org.apache.tuscany.sca.provider.ImplementationProvider; -import org.apache.tuscany.sca.provider.ImplementationProviderFactory; -import org.apache.tuscany.sca.provider.PolicyProvider; -import org.apache.tuscany.sca.provider.PolicyProviderFactory; -import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.EndpointReference; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentContext; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.apache.tuscany.sca.runtime.RuntimeWire; -import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; -import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; -import org.apache.tuscany.sca.work.WorkScheduler; - -/** - * @version $Rev$ $Date$ - */ -public class CompositeActivatorImpl implements CompositeActivator { - private static final Logger logger = Logger.getLogger(CompositeActivatorImpl.class.getName()); - - private final AssemblyFactory assemblyFactory; - private final MessageFactory messageFactory; - private final InterfaceContractMapper interfaceContractMapper; - private final ScopeRegistry scopeRegistry; - private final WorkScheduler workScheduler; - private final RuntimeWireProcessor wireProcessor; - private final ProviderFactoryExtensionPoint providerFactories; - private final EndpointResolverFactoryExtensionPoint endpointResolverFactories; - - private final ComponentContextFactory componentContextFactory; - private final RequestContextFactory requestContextFactory; - private final ProxyFactory proxyFactory; - private final JavaInterfaceFactory javaInterfaceFactory; - private final PropertyValueFactory propertyValueFactory; - - private final ConversationManager conversationManager; - - private final CompositeContext compositeContext; - - private Composite domainComposite; - - public CompositeActivatorImpl(ExtensionPointRegistry extensionPoints) { - this.compositeContext = new CompositeContextImpl(extensionPoints); - FactoryExtensionPoint factories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - this.assemblyFactory = factories.getFactory(AssemblyFactory.class); - this.messageFactory = factories.getFactory(MessageFactory.class); - UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); - this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); - this.scopeRegistry = utilities.getUtility(ScopeRegistry.class); - this.workScheduler = utilities.getUtility(WorkScheduler.class); - this.wireProcessor = new ExtensibleWireProcessor(extensionPoints.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class)); - this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); - this.endpointResolverFactories = extensionPoints.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); - this.javaInterfaceFactory = compositeContext.getJavaInterfaceFactory(); - this.propertyValueFactory = factories.getFactory(PropertyValueFactory.class); - ContextFactoryExtensionPoint contextFactories = extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class); - this.componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class); - this.requestContextFactory = contextFactories.getFactory(RequestContextFactory.class); - proxyFactory = compositeContext.getProxyFactory(); - this.conversationManager = compositeContext.getConversationManager(); - } - - /** - * @see org.apache.tuscany.sca.core.assembly.CompositeActivator#activate(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference) - */ - public void activate(RuntimeComponent component, RuntimeComponentReference ref) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Activating component reference: " + component.getURI() + "#" + ref.getName()); - } - resolveTargets(ref); - for (Binding binding : ref.getBindings()) { - addReferenceBindingProvider(component, ref, binding); - } - - for (Endpoint endpoint : ref.getEndpoints()){ - // TODO - source component should be set in the builder but the - // way the builder is written it's difficult to get at it - endpoint.setSourceComponent(component); - - addEndpointResolver(component, ref, endpoint); - } - } - - public void start(RuntimeComponent component, RuntimeComponentReference ref) { - synchronized (ref) { - resolveTargets(ref); - for (Binding binding : ref.getBindings()) { - ReferenceBindingProvider provider = ref.getBindingProvider(binding); - if (provider == null) { - provider = addReferenceBindingProvider(component, ref, binding); - } - if (provider != null) { - provider.start(); - } - addReferenceWire(component, ref, binding); - } - - // targets now have an endpoint representation. We can use this to - // look for unresolved endpoints using dummy wires for late resolution - for (Endpoint endpoint : ref.getEndpoints()){ - addReferenceEndpointWire(component, ref, endpoint); - } - } - } - - public void stop(Component component, ComponentReference reference) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName()); - } - RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); - for (Binding binding : reference.getBindings()) { - ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); - if (bindingProvider != null) { - bindingProvider.stop(); - } - } - } - - public void deactivate(RuntimeComponent component, RuntimeComponentReference ref) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Deactivating component reference: " + component.getURI() + "#" + ref.getName()); - } - removeReferenceWires(ref); - for (Binding binding : ref.getBindings()) { - removeReferenceBindingProvider(component, ref, binding); - } - - } - - /** - * @param component - * @param reference - * @param binding - */ - private EndpointResolver addEndpointResolver(RuntimeComponent component, - RuntimeComponentReference reference, - Endpoint endpoint){ - - // only create endpoint resolvers for unresolved endpoints currently - // this will also prevent a wire from being created later - if (!endpoint.isUnresolved()){ - return null; - } - - // This souldn't happen as the endpoint resolver extension point is in core-spi but - // just in case returning null here will mean that no wire is created and calling - // the reference will fail with NPE - if (endpointResolverFactories == null){ - return null; - } - - EndpointResolverFactory<Endpoint> resolverFactory = - (EndpointResolverFactory<Endpoint>)endpointResolverFactories.getEndpointResolverFactory(endpoint.getClass()); - - if (resolverFactory != null) { - EndpointResolver endpointResolver = - resolverFactory.createEndpointResolver(endpoint, null); - if (endpointResolver != null) { - ((RuntimeComponentReference)reference).setEndpointResolver(endpoint, endpointResolver); - } - - return endpointResolver; - } else { - // TODO - for the time being allow the lack of an endpoint provider to be the - // switch to turn off endpoint processing - return null; - //throw new IllegalStateException("Endpoint provider factory not found for class: " + endpoint.getClass().getName()); - } - } - - public void addReferenceBindingProviderForEndpoint(Endpoint endpoint){ - addReferenceBindingProvider((RuntimeComponent)endpoint.getSourceComponent(), - (RuntimeComponentReference)endpoint.getSourceComponentReference(), - endpoint.getSourceBinding()); - } - - /** - * @param component - * @param reference - * @param binding - */ - private ReferenceBindingProvider addReferenceBindingProvider(RuntimeComponent component, - RuntimeComponentReference reference, - Binding binding) { - BindingProviderFactory providerFactory = - (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass()); - if (providerFactory != null) { - @SuppressWarnings("unchecked") - ReferenceBindingProvider bindingProvider = - providerFactory.createReferenceBindingProvider((RuntimeComponent)component, - (RuntimeComponentReference)reference, - binding); - if (bindingProvider != null) { - ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider); - } - for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) { - PolicyProvider policyProvider = f.createReferencePolicyProvider(component, reference, binding); - if (policyProvider != null) { - reference.addPolicyProvider(binding, policyProvider); - } - } - - return bindingProvider; - } else { - throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName()); - } - } - - /** - * @param reference - */ - private void resolveTargets(RuntimeComponentReference reference) { - // The code that used to be here to resolved unresolved targets is now - // at the bottom of BaseWireBuilder.connectComponentReferences() - } - - /** - * Create the runtime wires for a reference endpoint. Currently this method - * only deals with the late binding case and creates a dummy wire that - * will use the Endpoint to resolve the target at the point when the - * wire chains are created. - * - * @param component - * @param reference - * @param binding - */ - private void addReferenceEndpointWire(Component component, ComponentReference reference, Endpoint endpoint) { - // only deal with unresolved endpoints as, to prevent breaking changes, targets that are resolved - // at build time are still represented as bindings in the binding list - if (((RuntimeComponentReference)reference).getEndpointResolver(endpoint) == null){ - // no endpoint provider has previously been created so don't create the - // wire - return; - } - - // TODO: TUSCANY-2580: avoid NPE if the InterfaceCOntract is null - Reference ctref = endpoint.getSourceComponentReference().getReference(); - if (ctref != null && ctref.getInterfaceContract() == null) { - ctref.setInterfaceContract(reference.getInterfaceContract()); - } - - RuntimeWire wire = new EndpointWireImpl(endpoint, this); - - RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; - runtimeRef.getRuntimeWires().add(wire); - } - - - /** - * Create the runtime wires for a reference binding - * - * @param component - * @param reference - * @param binding - */ - private void addReferenceWire(Component component, ComponentReference reference, Binding binding) { - if (!(reference instanceof RuntimeComponentReference)) { - return; - } - - // create wire if binding has an endpoint - Component targetComponent = null; - ComponentService targetComponentService = null; - Binding targetBinding = null; - - if (binding instanceof OptimizableBinding) { - OptimizableBinding endpoint = (OptimizableBinding)binding; - targetComponent = endpoint.getTargetComponent(); - targetComponentService = endpoint.getTargetComponentService(); - targetBinding = endpoint.getTargetBinding(); - // FIXME: TUSCANY-2136, For unresolved binding, don't add wire. Is it the right solution? - if (!reference.isCallback() && binding.getURI() == null && targetComponentService == null) { - return; - } - } - - // create a forward wire, either static or dynamic - addReferenceWire(component, reference, binding, targetComponent, targetComponentService, targetBinding); - - /* - // if static forward wire (not from self-reference), try to create a static callback wire - if (targetComponentService != null && !reference.getName().startsWith("$self$.")) { - ComponentReference callbackReference = targetComponentService.getCallbackReference(); - if (callbackReference != null) { - Binding callbackBinding = null; - Binding callbackServiceBinding = null; - // select a service callback binding that can be wired back to this component - for (Binding refBinding : callbackReference.getBindings()) { - // first look for a callback binding whose name matches the target binding name - if (refBinding.getName().equals(targetBinding.getName())) { - callbackBinding = refBinding; - break; - } - } - // see if there is a matching reference callback binding - if (callbackBinding != null) { - callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass()); - } - // if there isn't an end-to-end match, try again based on target binding type - if (callbackBinding == null || callbackServiceBinding == null) { - callbackBinding = callbackReference.getBinding(targetBinding.getClass()); - if (callbackBinding != null) { - callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass()); - } - } - if (callbackBinding != null && callbackServiceBinding != null) { - // end-to-end match, so create a static callback wire as well as the static forward wire - - addReferenceWire(targetComponent, callbackReference, callbackBinding, component, reference - .getCallbackService(), callbackServiceBinding); - } else { - // no end-to-end match, so do not create a static callback wire - } - } - } - */ - } - - public void addReferenceWireForEndpoint(Endpoint endpoint){ - addReferenceWire(endpoint.getSourceComponent(), - endpoint.getSourceComponentReference(), - endpoint.getSourceBinding(), - endpoint.getTargetComponent(), - endpoint.getTargetComponentService(), - endpoint.getTargetBinding()); - } - /** - * Create a reference wire for a forward call or a callback - * @param reference - * @param service - * @param serviceBinding - * @param component - * @param referenceBinding - */ - private RuntimeWire addReferenceWire(Component refComponent, - ComponentReference reference, - Binding refBinding, - Component serviceComponent, - ComponentService service, - Binding serviceBinding) { - RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; - InterfaceContract bindingContract = getInterfaceContract(reference, refBinding); - - // Use the interface contract of the reference on the component type - Reference componentTypeRef = reference.getReference(); - - InterfaceContract sourceContract; - if (componentTypeRef == null || componentTypeRef.getInterfaceContract() == null) { - sourceContract = reference.getInterfaceContract(); - } else { - sourceContract = componentTypeRef.getInterfaceContract(); - } - - sourceContract = sourceContract.makeUnidirectional(false); - - EndpointReference wireSource = - new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract); - ComponentService callbackService = reference.getCallbackService(); - if (callbackService != null) { - // select a reference callback binding to pass with invocations on this wire - Binding callbackBinding = null; - for (Binding binding : callbackService.getBindings()) { - // first look for a callback binding whose name matches the reference binding name - if (refBinding.getName().startsWith(binding.getName())) { - callbackBinding = binding; - break; - } - } - // if no callback binding found, try again based on reference binding type - if (callbackBinding == null) { - callbackBinding = callbackService.getBinding(refBinding.getClass()); - } - InterfaceContract callbackContract = callbackService.getInterfaceContract(); - EndpointReference callbackEndpoint = - new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding, - callbackContract); - wireSource.setCallbackEndpoint(callbackEndpoint); - } - - EndpointReference wireTarget = - new EndpointReferenceImpl((RuntimeComponent)serviceComponent, service, serviceBinding, bindingContract); - - // TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a - // nested composite. - if (serviceBinding != null) { - wireTarget.setURI(serviceBinding.getURI()); - } - - RuntimeWire wire = - new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor, - messageFactory, conversationManager); - runtimeRef.getRuntimeWires().add(wire); - - return wire; - } - - private void addImplementationProvider(RuntimeComponent component, Implementation implementation) { - ImplementationProviderFactory providerFactory = - (ImplementationProviderFactory)providerFactories.getProviderFactory(implementation.getClass()); - if (providerFactory != null) { - @SuppressWarnings("unchecked") - ImplementationProvider implementationProvider = - providerFactory.createImplementationProvider(component, implementation); - if (implementationProvider != null) { - component.setImplementationProvider(implementationProvider); - } - } else { - throw new IllegalStateException("Provider factory not found for class: " + implementation.getClass() - .getName()); - } - for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) { - PolicyProvider policyProvider = f.createImplementationPolicyProvider(component, implementation); - if (policyProvider != null) { - component.addPolicyProvider(policyProvider); - } - } - - } - - private void removeImplementationProvider(RuntimeComponent component) { - component.setImplementationProvider(null); - component.getPolicyProviders().clear(); - } - - /** - * @param component - * @param service - * @param binding - */ - private ServiceBindingProvider addServiceBindingProvider(RuntimeComponent component, - RuntimeComponentService service, - Binding binding) { - BindingProviderFactory providerFactory = - (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass()); - if (providerFactory != null) { - @SuppressWarnings("unchecked") - ServiceBindingProvider bindingProvider = - providerFactory.createServiceBindingProvider((RuntimeComponent)component, - (RuntimeComponentService)service, - binding); - if (bindingProvider != null) { - ((RuntimeComponentService)service).setBindingProvider(binding, bindingProvider); - } - for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) { - PolicyProvider policyProvider = f.createServicePolicyProvider(component, service, binding); - if (policyProvider != null) { - service.addPolicyProvider(binding, policyProvider); - } - } - return bindingProvider; - } else { - throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName()); - } - } - - private void removeServiceBindingProvider(RuntimeComponent component, - RuntimeComponentService service, - Binding binding) { - service.setBindingProvider(binding, null); - for (Binding b : service.getBindings()) { - List<PolicyProvider> pps = service.getPolicyProviders(b); - if (pps != null) { - pps.clear(); - } - } - } - - private void removeReferenceBindingProvider(RuntimeComponent component, - RuntimeComponentReference reference, - Binding binding) { - reference.setBindingProvider(binding, null); - for (Binding b : reference.getBindings()) { - List<PolicyProvider> pps = reference.getPolicyProviders(b); - if (pps != null) { - pps.clear(); - } - } - } - - public void start(Composite composite) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Starting composite: " + composite.getName()); - } - for (Component component : composite.getComponents()) { - start(component); - } - } - - public void stop(Composite composite) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Stopping composite: " + composite.getName()); - } - for (final Component component : composite.getComponents()) { - stop(component); - } - } - - public void start(Component component) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Starting component: " + component.getURI()); - } - RuntimeComponent runtimeComponent = ((RuntimeComponent)component); - if(runtimeComponent.isStarted()) { - return; - } - - configureComponentContext(runtimeComponent); - - for (ComponentReference reference : component.getReferences()) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName()); - } - RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); - runtimeRef.setComponent(runtimeComponent); - - for (Endpoint endpoint : reference.getEndpoints()) { - final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint); - if (endpointResolver != null) { - // Allow endpoint resolvers to do any startup reference manipulation - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - endpointResolver.start(); - return null; - } - }); - } - } - - for (Binding binding : reference.getBindings()) { - final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); - if (bindingProvider != null) { - // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - bindingProvider.start(); - return null; - } - }); - } - } - } - - for (ComponentService service : component.getServices()) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Starting component service: " + component.getURI() + "#" + service.getName()); - } - RuntimeComponentService runtimeService = (RuntimeComponentService)service; - for (Binding binding : service.getBindings()) { - final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(binding); - if (bindingProvider != null) { - // bindingProvider.start(); - // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - bindingProvider.start(); - return null; - } - }); - } - } - } - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - start((Composite)implementation); - } else { - ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider(); - if (implementationProvider != null) { - implementationProvider.start(); - } - } - - if (component instanceof ScopedRuntimeComponent) { - ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component; - if (scopedRuntimeComponent.getScopeContainer() != null) { - scopedRuntimeComponent.getScopeContainer().start(); - } - } - - runtimeComponent.setStarted(true); - } - - /** - * @param runtimeComponent - */ - public void configureComponentContext(RuntimeComponent runtimeComponent) { - RuntimeComponentContext componentContext = (RuntimeComponentContext) componentContextFactory.createComponentContext(runtimeComponent); - runtimeComponent.setComponentContext(componentContext); - } - - /** - * Stop a component - */ - public void stop(Component component) { - if (!((RuntimeComponent)component).isStarted()) { - return; - } - if (logger.isLoggable(Level.FINE)) { - logger.fine("Stopping component: " + component.getURI()); - } - for (ComponentService service : component.getServices()) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName()); - } - for (Binding binding : service.getBindings()) { - final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(binding); - if (bindingProvider != null) { - // Allow bindings to read properties. Requires PropertyPermission read in security policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - bindingProvider.stop(); - return null; - } - }); - } - } - } - for (ComponentReference reference : component.getReferences()) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName()); - } - RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference); - - for (Binding binding : reference.getBindings()) { - final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); - if (bindingProvider != null) { - // Allow bindings to read properties. Requires PropertyPermission read in security policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - bindingProvider.stop(); - return null; - } - }); - } - } - - for (Endpoint endpoint : reference.getEndpoints()) { - final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint); - if (endpointResolver != null) { - // Allow endpoint resolvers to do any shutdown reference manipulation - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - endpointResolver.stop(); - return null; - } - }); - } - } - } - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - stop((Composite)implementation); - } else { - final ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider(); - if (implementationProvider != null) { - // Allow bindings to read properties. Requires PropertyPermission read in security policy. - AccessController.doPrivileged(new PrivilegedAction<Object>() { - public Object run() { - implementationProvider.stop(); - return null; - } - }); - } - } - - if (component instanceof ScopedRuntimeComponent) { - ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; - if (runtimeComponent.getScopeContainer() != null && - runtimeComponent.getScopeContainer().getLifecycleState() != ScopeContainer.STOPPED) { - runtimeComponent.getScopeContainer().stop(); - } - } - - ((RuntimeComponent)component).setStarted(false); - } - - /** - * Get the effective interface contract for a reference binding - * - * @param reference - * @param binding - * @return - */ - private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) { - InterfaceContract interfaceContract = reference.getInterfaceContract(); - ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); - if (provider != null) { - InterfaceContract bindingContract = provider.getBindingInterfaceContract(); - if (bindingContract != null) { - interfaceContract = bindingContract; - } - } - return interfaceContract.makeUnidirectional(false); - } - - /** - * Remove the runtime wires for a reference binding - * @param reference - */ - private void removeReferenceWires(ComponentReference reference) { - if (!(reference instanceof RuntimeComponentReference)) { - return; - } - // [rfeng] Comment out the following statements to avoid the on-demand activation - // RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; - // runtimeRef.getRuntimeWires().clear(); - } - - /** - * Get the effective interface contract for the service binding - * - * @param service - * @param binding - * @return - */ - private InterfaceContract getInterfaceContract(ComponentService service, Binding binding) { - InterfaceContract interfaceContract = service.getInterfaceContract(); - - ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding); - if (provider != null) { - InterfaceContract bindingContract = provider.getBindingInterfaceContract(); - if (bindingContract != null) { - interfaceContract = bindingContract; - } - } - return interfaceContract.makeUnidirectional(false); - } - - /** - * Remove runtime wires for a service binding - * - * @param component - * @param service - */ - private void removeServiceWires(ComponentService service) { - if (!(service instanceof RuntimeComponentService)) { - return; - } - RuntimeComponentService runtimeService = (RuntimeComponentService)service; - runtimeService.getRuntimeWires().clear(); - } - - /** - * Create a service wire for a forward call or a callback - * @param service - * @param serviceBinding - * @param reference - * @param component - * @param referenceBinding - */ - private RuntimeWire addServiceWire(Component serviceComponent, ComponentService service, Binding serviceBinding) { - if (!(service instanceof RuntimeComponentService)) { - return null; - } - RuntimeComponentService runtimeService = (RuntimeComponentService)service; - - // FIXME: [rfeng] We might need a better way to get the impl interface contract - Service targetService = service.getService(); - if (targetService == null) { - targetService = service; - } - InterfaceContract targetContract = targetService.getInterfaceContract().makeUnidirectional(false); - - InterfaceContract sourceContract = getInterfaceContract(service, serviceBinding); - - EndpointReference wireSource = new EndpointReferenceImpl(null, null, serviceBinding, sourceContract); - - EndpointReference wireTarget = - new EndpointReferenceImpl((RuntimeComponent)serviceComponent, (RuntimeComponentService)service, - serviceBinding, targetContract); - - RuntimeWire wire = - new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor, - messageFactory, conversationManager); - runtimeService.getRuntimeWires().add(wire); - - return wire; - } - - public void activate(RuntimeComponent component, RuntimeComponentService service) { - if (service.getService() == null) { - if (logger.isLoggable(Level.WARNING)) { - logger.warning("Skipping component service not defined in the component type: " + component.getURI() - + "#" - + service.getName()); - } - return; - } - if (service.getService() instanceof CompositeService) { - return; - } - if (logger.isLoggable(Level.FINE)) { - logger.fine("Activating component service: " + component.getURI() + "#" + service.getName()); - } - - for (Binding binding : service.getBindings()) { - addServiceBindingProvider(component, service, binding); - addServiceWire(component, service, binding); - } - } - - public void deactivate(RuntimeComponent component, RuntimeComponentService service) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Deactivating component service: " + component.getURI() + "#" + service.getName()); - } - removeServiceWires(service); - for (Binding binding : service.getBindings()) { - removeServiceBindingProvider(component, service, binding); - } - } - - private void addScopeContainer(Component component) { - if (!(component instanceof ScopedRuntimeComponent)) { - return; - } - ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; - ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(runtimeComponent); - if (scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) { - conversationManager.addListener((ConversationalScopeContainer)scopeContainer); - } - runtimeComponent.setScopeContainer(scopeContainer); - } - - private void removeScopeContainer(Component component) { - if (!(component instanceof ScopedRuntimeComponent)) { - return; - } - ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; - ScopeContainer scopeContainer = runtimeComponent.getScopeContainer(); - if(scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) { - conversationManager.removeListener((ConversationalScopeContainer) scopeContainer); - } - runtimeComponent.setScopeContainer(null); - } - - public void activateComponent(Component component) - throws ActivationException { - try { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Activating component: " + component.getURI()); - } - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - activate((Composite) implementation); - } else if (implementation != null) { - addImplementationProvider((RuntimeComponent) component, - implementation); - addScopeContainer(component); - } - - for (ComponentService service : component.getServices()) { - activate((RuntimeComponent) component, - (RuntimeComponentService) service); - } - - for (ComponentReference reference : component.getReferences()) { - activate((RuntimeComponent) component, - (RuntimeComponentReference) reference); - } - } catch (Exception e) { - throw new ActivationException(e); - } - } - - public void deactivateComponent(Component component) - throws ActivationException { - try { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Deactivating component: " + component.getURI()); - } - for (ComponentService service : component.getServices()) { - deactivate((RuntimeComponent) component, - (RuntimeComponentService) service); - } - - for (ComponentReference reference : component.getReferences()) { - deactivate((RuntimeComponent) component, - (RuntimeComponentReference) reference); - } - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - deactivate((Composite) implementation); - } else if (implementation != null) { - removeImplementationProvider((RuntimeComponent) component); - removeScopeContainer(component); - } - } catch (Exception e) { - throw new ActivationException(e); - } - } - - public void activate(Composite composite) throws ActivationException { - try { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Activating composite: " + composite.getName()); - } - for (Component component : composite.getComponents()) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Activating component: " + component.getURI()); - } - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - activate((Composite)implementation); - } else if (implementation != null) { - addImplementationProvider((RuntimeComponent)component, implementation); - addScopeContainer(component); - } - - for (ComponentService service : component.getServices()) { - activate((RuntimeComponent)component, (RuntimeComponentService)service); - } - - for (ComponentReference reference : component.getReferences()) { - activate((RuntimeComponent)component, (RuntimeComponentReference)reference); - } - } - } catch (Exception e) { - throw new ActivationException(e); - } - } - - public void deactivate(Composite composite) throws ActivationException { - try { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Deactivating composite: " + composite.getName()); - } - for (Component component : composite.getComponents()) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Deactivating component: " + component.getURI()); - } - for (ComponentService service : component.getServices()) { - deactivate((RuntimeComponent)component, (RuntimeComponentService)service); - } - - for (ComponentReference reference : component.getReferences()) { - deactivate((RuntimeComponent)component, (RuntimeComponentReference)reference); - } - - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - deactivate((Composite)implementation); - } else if (implementation != null) { - removeImplementationProvider((RuntimeComponent)component); - removeScopeContainer(component); - } - } - } catch (Exception e) { - throw new ActivationException(e); - } - } - - /** - * @return the referenceHelper - */ - public CompositeContext getCompositeContext() { - return compositeContext; - } - - /** - * @return the domainComposite - */ - public Composite getDomainComposite() { - return domainComposite; - } - - /** - * @param domainComposite the domainComposite to set - */ - public void setDomainComposite(Composite domainComposite) { - this.domainComposite = domainComposite; - } - - public Component resolve(String componentURI) { - for (Composite composite : domainComposite.getIncludes()) { - Component component = resolve(composite, componentURI); - if (component != null) { - return component; - } - } - return null; - } - - public Component resolve(Composite composite, String componentURI) { - for (Component component : composite.getComponents()) { - String uri = component.getURI(); - if (uri.equals(componentURI)) { - return component; - } - if (componentURI.startsWith(uri)) { - Implementation implementation = component.getImplementation(); - if (!(implementation instanceof Composite)) { - return null; - } - return resolve((Composite)implementation, componentURI); - } - } - return null; - } - -} diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java index f36c0ce301..de304ac3b5 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl2.java @@ -55,7 +55,6 @@ import org.apache.tuscany.sca.core.scope.ScopeContainer; import org.apache.tuscany.sca.core.scope.ScopeRegistry; import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent; import org.apache.tuscany.sca.core.scope.impl.ConversationalScopeContainer; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; @@ -90,7 +89,6 @@ public class CompositeActivatorImpl2 implements CompositeActivator { private final WorkScheduler workScheduler; private final RuntimeWireProcessor wireProcessor; private final ProviderFactoryExtensionPoint providerFactories; - private final EndpointResolverFactoryExtensionPoint endpointResolverFactories; private final ComponentContextFactory componentContextFactory; private final RequestContextFactory requestContextFactory; @@ -115,7 +113,6 @@ public class CompositeActivatorImpl2 implements CompositeActivator { this.workScheduler = utilities.getUtility(WorkScheduler.class); this.wireProcessor = new ExtensibleWireProcessor(extensionPoints.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class)); this.providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class); - this.endpointResolverFactories = extensionPoints.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); this.javaInterfaceFactory = compositeContext.getJavaInterfaceFactory(); this.propertyValueFactory = factories.getFactory(PropertyValueFactory.class); ContextFactoryExtensionPoint contextFactories = extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class); diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointWireImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointWireImpl.java deleted file mode 100644 index 1e11c7062e..0000000000 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/EndpointWireImpl.java +++ /dev/null @@ -1,191 +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.core.assembly.impl; - -import java.lang.reflect.InvocationTargetException; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointReference2; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.core.invocation.impl.InvocationChainImpl; -import org.apache.tuscany.sca.endpointresolver.EndpointResolver; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.InvocationChain; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.runtime.EndpointReference; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeWire; -import org.oasisopen.sca.ServiceUnavailableException; - -/** - * @version $Rev$ $Date$ - */ -public class EndpointWireImpl implements RuntimeWire { - - private Endpoint endpoint; - private CompositeActivatorImpl compositeActivator; - - private EndpointResolver endpointResolver; - private EndpointReference source; - private RuntimeWire wire; - private InvocationChain binidngInvocationChain; - - /** - * @param endpoint - */ - public EndpointWireImpl(Endpoint endpoint, CompositeActivator compositeActivator) { - super(); - this.endpoint = endpoint; - // TODO - improve the SPI to get rid of this cast - this.compositeActivator = (CompositeActivatorImpl)compositeActivator; - - // store source configuration as we have most of this now. We don't though know what the - // target is yet. - Reference componentTypeRef = endpoint.getSourceComponentReference().getReference(); - InterfaceContract sourceContract = - componentTypeRef == null ? endpoint.getSourceComponentReference().getInterfaceContract() : componentTypeRef.getInterfaceContract(); - sourceContract = sourceContract.makeUnidirectional(false); - - source = new EndpointReferenceImpl((RuntimeComponent)endpoint.getSourceComponent(), - endpoint.getSourceComponentReference(), - null, - sourceContract); - - RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference()); - endpointResolver = runtimeRef.getEndpointResolver(endpoint); - - } - - public synchronized List<InvocationChain> getInvocationChains() { - // where late binding happens. Find the endpoint provider and - // ask it to do the endpoint resolution. - if (endpoint.isUnresolved()){ - - // this method should locate a viable target service and complete the - // endpoint configuration - endpointResolver.resolve(); - - if (endpoint.isUnresolved()){ - throw new ServiceUnavailableException("Unable to resolve service for component: " + - endpoint.getSourceComponent().getName() + - " reference: " + - endpoint.getSourceComponentReference().getName() + - " target: " + - endpoint.getTargetName()); - } - } - - if (wire == null){ - RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference()); - - // add the resolved binding into the reference - runtimeRef.getBindings().add(endpoint.getSourceBinding()); - - // add a binding provider into the reference for the resolved binding - compositeActivator.addReferenceBindingProviderForEndpoint(endpoint); - - // extract the binding provider that has been created - ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpoint.getSourceBinding()); - - // start the binding provider - bindingProvider.start(); - - // create the wire - compositeActivator.addReferenceWireForEndpoint(endpoint); - - // extract the wire that has been created - wire = runtimeRef.getRuntimeWire(endpoint.getSourceBinding()); - } - - return wire.getInvocationChains(); - } - - public InvocationChain getInvocationChain(Operation operation) { - if (wire ==null){ - return null; - } else { - return wire.getInvocationChain(operation); - } - } - - public Object invoke(Message msg) throws InvocationTargetException { - // not called as the endpoint wire only appears on the reference side - return null; - } - - public Object invoke(Operation operation, Object[] args) throws InvocationTargetException { - // not called as the endpoint wire only appears on the reference side - return null; - } - - public Object invoke(Operation operation, Message msg) throws InvocationTargetException { - // not called as the endpoint wire only appears on the reference side - return null; - } - - - public EndpointReference getSource() { - return source; - } - - public EndpointReference getTarget() { - return null; - } - - public void setTarget(EndpointReference target) { - } - - public void rebuild() { - } - - public synchronized InvocationChain getBindingInvocationChain() { - if (binidngInvocationChain == null) { - if (source instanceof RuntimeComponentReference) { - binidngInvocationChain = new InvocationChainImpl(null, null, true); - } else { - binidngInvocationChain = new InvocationChainImpl(null, null, false); - } - } - return binidngInvocationChain; - } - - // TODO: TUSCANY-2580: give RuntimeComponentReferenceImpl a way to get at the endpoint - public Endpoint getEndpoint() { - return endpoint; - } - - /** - * @see java.lang.Object#clone() - */ - @Override - public Object clone() throws CloneNotSupportedException { - EndpointWireImpl copy = (EndpointWireImpl)super.clone(); - return copy; - } - - public EndpointReference2 getEndpointReference(){ - return null; - } -} diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java index 994094ab23..dbdba54dc0 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeComponentReferenceImpl.java @@ -24,10 +24,8 @@ import java.util.HashMap; import java.util.List; import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl; -import org.apache.tuscany.sca.endpointresolver.EndpointResolver; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; @@ -45,9 +43,7 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference { private ArrayList<RuntimeWire> wires; private HashMap<Binding, ReferenceBindingProvider> bindingProviders = - new HashMap<Binding, ReferenceBindingProvider>(); - private HashMap<Endpoint, EndpointResolver> endpointResolvers = - new HashMap<Endpoint, EndpointResolver>(); + new HashMap<Binding, ReferenceBindingProvider>(); private HashMap<Binding, List<PolicyProvider>> policyProviders = new HashMap<Binding, List<PolicyProvider>>(); private RuntimeComponent component; @@ -93,14 +89,6 @@ public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implem bindingProviders.put(binding, bindingProvider); } - public EndpointResolver getEndpointResolver(Endpoint endpoint){ - return endpointResolvers.get(endpoint); - } - - public void setEndpointResolver(Endpoint endpoint, EndpointResolver endpointResolver){ - endpointResolvers.put(endpoint, endpointResolver); - } - public Invoker getInvoker(Binding binding, Operation operation) { RuntimeWire wire = getRuntimeWire(binding); if (wire == null) { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java deleted file mode 100644 index a9ff97d770..0000000000 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/RuntimeWireImpl.java +++ /dev/null @@ -1,466 +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.core.assembly.impl; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.EndpointReference2; -import org.apache.tuscany.sca.core.conversation.ConversationManager; -import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; -import org.apache.tuscany.sca.core.invocation.RuntimeWireInvoker; -import org.apache.tuscany.sca.core.invocation.impl.InvocationChainImpl; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Interceptor; -import org.apache.tuscany.sca.invocation.InvocationChain; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.invocation.Phase; -import org.apache.tuscany.sca.provider.ImplementationProvider; -import org.apache.tuscany.sca.provider.PolicyProvider; -import org.apache.tuscany.sca.provider.PolicyProviderRRB; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.provider.ReferenceBindingProviderRRB; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.provider.ServiceBindingProviderRRB; -import org.apache.tuscany.sca.runtime.EndpointReference; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.apache.tuscany.sca.runtime.RuntimeWire; -import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; -import org.apache.tuscany.sca.work.WorkScheduler; -import org.oasisopen.sca.ServiceRuntimeException; - -/** - * @version $Rev$ $Date$ - */ -public class RuntimeWireImpl implements RuntimeWire { - private EndpointReference wireSource; - private EndpointReference wireTarget; - - private transient RuntimeWireProcessor wireProcessor; - private transient InterfaceContractMapper interfaceContractMapper; - private transient WorkScheduler workScheduler; - private transient MessageFactory messageFactory; - private transient ConversationManager conversationManager; - private transient RuntimeWireInvoker invoker; - - // the following is a very simple cache that avoids re-cloning a wire - // when consecutive callbacks to the same endpoint are made - private EndpointReference lastCallback; - private RuntimeWire cachedWire; - private boolean wireReserved; - private RuntimeWireImpl clonedFrom; - - private List<InvocationChain> chains; - private InvocationChain bindingInvocationChain; - - /** - * @param source - * @param target - * @param interfaceContractMapper - * @param workScheduler - * @param wireProcessor - * @param messageFactory - * @param conversationManager - */ - public RuntimeWireImpl(EndpointReference source, - EndpointReference target, - InterfaceContractMapper interfaceContractMapper, - WorkScheduler workScheduler, - RuntimeWireProcessor wireProcessor, - MessageFactory messageFactory, - ConversationManager conversationManager) { - super(); - this.wireSource = source; - this.wireTarget = target; - this.interfaceContractMapper = interfaceContractMapper; - this.workScheduler = workScheduler; - this.wireProcessor = wireProcessor; - this.messageFactory = messageFactory; - this.conversationManager = conversationManager; - this.invoker = new RuntimeWireInvoker(this.messageFactory, this.conversationManager, this); - } - - public synchronized List<InvocationChain> getInvocationChains() { - if (chains == null) { - initInvocationChains(); - } - return chains; - } - - public synchronized InvocationChain getBindingInvocationChain() { - if (bindingInvocationChain == null) { - Contract source = wireSource.getContract(); - if (source instanceof RuntimeComponentReference) { - bindingInvocationChain = new InvocationChainImpl(null, null, true); - initReferenceBindingInvocationChains(); - } else { - bindingInvocationChain = new InvocationChainImpl(null, null, false); - initServiceBindingInvocationChains(); - } - } - return bindingInvocationChain; - } - - public InvocationChain getInvocationChain(Operation operation) { - for (InvocationChain chain : getInvocationChains()) { - Operation op = null; - if (wireSource.getContract() != null) { - // Reference chain - op = chain.getSourceOperation(); - } else { - // Service chain - op = chain.getTargetOperation(); - } - if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) { - return chain; - } - } - return null; - } - - public Object invoke(Message msg) throws InvocationTargetException { - return getBindingInvocationChain().getHeadInvoker().invoke(msg); - } - - public Object invoke(Operation operation, Object[] args) throws InvocationTargetException { - Message msg = messageFactory.createMessage(); - msg.setBody(args); - return invoker.invoke(operation, msg); - } - - public Object invoke(Operation operation, Message msg) throws InvocationTargetException { - return invoker.invoke(operation, msg); - } - - /** - * Initialize the invocation chains - */ - private void initInvocationChains() { - chains = new ArrayList<InvocationChain>(); - InterfaceContract sourceContract = wireSource.getInterfaceContract(); - InterfaceContract targetContract = wireTarget.getInterfaceContract(); - - Contract source = wireSource.getContract(); - if (source instanceof RuntimeComponentReference) { - // It's the reference wire - RuntimeComponentReference reference = (RuntimeComponentReference)wireSource.getContract(); - Binding refBinding = wireSource.getBinding(); - for (Operation operation : sourceContract.getInterface().getOperations()) { - Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); - if (targetOperation == null) { - throw new ServiceRuntimeException("No matching operation for " + operation.getName() - + " is found in reference " - + wireSource.getComponent().getURI() - + "#" - + reference.getName()); - } - InvocationChain chain = new InvocationChainImpl(operation, targetOperation, true); - if (operation.isNonBlocking()) { - addNonBlockingInterceptor(reference, refBinding, chain); - } - addReferenceBindingInterceptor(reference, refBinding, chain, operation); - chains.add(chain); - } - - } else { - // It's the service wire - RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract(); - RuntimeComponent serviceComponent = wireTarget.getComponent(); - Binding serviceBinding = wireTarget.getBinding(); - for (Operation operation : sourceContract.getInterface().getOperations()) { - Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); - if (targetOperation == null) { - throw new ServiceRuntimeException("No matching operation for " + operation.getName() - + " is found in service " - + serviceComponent.getURI() - + "#" - + service.getName()); - } - InvocationChain chain = new InvocationChainImpl(operation, targetOperation, false); - if (operation.isNonBlocking()) { - addNonBlockingInterceptor(service, serviceBinding, chain); - } - addServiceBindingInterceptor(service, serviceBinding, chain, operation); - addImplementationInterceptor(serviceComponent, service, chain, targetOperation); - chains.add(chain); - } - - } - wireProcessor.process(this); - } - - private void initReferenceBindingInvocationChains() { - RuntimeComponentReference reference = (RuntimeComponentReference)wireSource.getContract(); - Binding referenceBinding = wireSource.getBinding(); - - // add the binding interceptors to the reference binding wire - ReferenceBindingProvider provider = reference.getBindingProvider(referenceBinding); - if ((provider != null) && - (provider instanceof ReferenceBindingProviderRRB)){ - ((ReferenceBindingProviderRRB)provider).configureBindingChain(this); - } - - // add the policy interceptors to the service binding wire - // find out which policies are active - List<PolicyProvider> pps = ((RuntimeComponentReference)reference).getPolicyProviders(referenceBinding); - if (pps != null) { - for (PolicyProvider p : pps) { - if (p instanceof PolicyProviderRRB) { - Interceptor interceptor = ((PolicyProviderRRB)p).createBindingInterceptor(); - if (interceptor != null) { - bindingInvocationChain.addInterceptor(p.getPhase(), interceptor); - } - } - } - } - } - - private void initServiceBindingInvocationChains() { - RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract(); - Binding serviceBinding = wireTarget.getBinding(); - - // add the binding interceptors to the service binding wire - ServiceBindingProvider provider = service.getBindingProvider(serviceBinding); - if ((provider != null) && - (provider instanceof ServiceBindingProviderRRB)){ - ((ServiceBindingProviderRRB)provider).configureBindingChain(this); - } - - // add the policy interceptors to the service binding wire - List<PolicyProvider> pps = ((RuntimeComponentService)service).getPolicyProviders(serviceBinding); - if (pps != null) { - for (PolicyProvider p : pps) { - if (p instanceof PolicyProviderRRB) { - Interceptor interceptor = ((PolicyProviderRRB)p).createBindingInterceptor(); - if (interceptor != null) { - bindingInvocationChain.addInterceptor(p.getPhase(), interceptor); - } - } - } - } - - - // TODO - add something on the end of the wire to invoke the - // invocation chain. Need to split out the runtime - // wire invoker into conversation, callback interceptors etc - bindingInvocationChain.addInvoker(invoker); - - } - - public EndpointReference getSource() { - return wireSource; - } - - public EndpointReference getTarget() { - return wireTarget; - } - - public void setTarget(EndpointReference target) { - if (this.wireTarget != target) { - rebuild(); - } - this.wireTarget = target; - } - - public void rebuild() { - this.chains = null; - } - - /** - * Add the interceptor for a reference binding - * - * @param reference - * @param binding - * @param chain - * @param operation - */ - private void addReferenceBindingInterceptor(ComponentReference reference, - Binding binding, - InvocationChain chain, - Operation operation) { - ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); - if (provider != null) { - Invoker invoker = provider.createInvoker(operation); - if (invoker != null) { - chain.addInvoker(invoker); - } - } - List<PolicyProvider> pps = ((RuntimeComponentReference)reference).getPolicyProviders(binding); - if (pps != null) { - for (PolicyProvider p : pps) { - Interceptor interceptor = p.createInterceptor(operation); - if (interceptor != null) { - chain.addInterceptor(p.getPhase(), p.createInterceptor(operation)); - } - } - } - } - - /** - * Add the interceptor for a binding - * - * @param reference - * @param binding - * @param chain - * @param operation - */ - private void addServiceBindingInterceptor(ComponentService service, - Binding binding, - InvocationChain chain, - Operation operation) { - List<PolicyProvider> pps = ((RuntimeComponentService)service).getPolicyProviders(binding); - if (pps != null) { - for (PolicyProvider p : pps) { - Interceptor interceptor = p.createInterceptor(operation); - if (interceptor != null) { - chain.addInterceptor(p.getPhase(), p.createInterceptor(operation)); - } - } - } - } - - /** - * Add a non-blocking interceptor if the reference binding needs it - * - * @param reference - * @param binding - * @param chain - */ - private void addNonBlockingInterceptor(ComponentReference reference, Binding binding, InvocationChain chain) { - ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); - if (provider != null) { - boolean supportsOneWayInvocation = provider.supportsOneWayInvocation(); - if (!supportsOneWayInvocation) { - chain.addInterceptor(Phase.REFERENCE, new NonBlockingInterceptor(workScheduler)); - } - } - } - - /** - * Add a non-blocking interceptor if the service binding needs it - * - * @param service - * @param binding - * @param chain - */ - private void addNonBlockingInterceptor(ComponentService service, Binding binding, InvocationChain chain) { - ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding); - if (provider != null) { - if (!provider.supportsOneWayInvocation()) { - chain.addInterceptor(Phase.SERVICE, new NonBlockingInterceptor(workScheduler)); - } - } - } - - /** - * Add the interceptor for a component implementation - * - * @param component - * @param service - * @param chain - * @param operation - */ - private void addImplementationInterceptor(Component component, - ComponentService service, - InvocationChain chain, - Operation operation) { - ImplementationProvider provider = ((RuntimeComponent)component).getImplementationProvider(); - if (provider != null) { - Invoker invoker = null; - invoker = provider.createInvoker((RuntimeComponentService)service, operation); - chain.addInvoker(invoker); - } - List<PolicyProvider> pps = ((RuntimeComponent)component).getPolicyProviders(); - if (pps != null) { - for (PolicyProvider p : pps) { - Interceptor interceptor = p.createInterceptor(operation); - if (interceptor != null) { - chain.addInterceptor(p.getPhase(), p.createInterceptor(operation)); - } - } - } - } - - /** - * @see java.lang.Object#clone() - */ - @Override - public Object clone() throws CloneNotSupportedException { - RuntimeWireImpl copy = (RuntimeWireImpl)super.clone(); - copy.wireSource = (EndpointReference)wireSource.clone(); - copy.wireTarget = (EndpointReference)wireTarget.clone(); - copy.invoker = new RuntimeWireInvoker(copy.messageFactory, copy.conversationManager, copy); - copy.cachedWire = null; // TUSCANY-2630 - return copy; - } - - /** - * @return the conversationManager - */ - public ConversationManager getConversationManager() { - return conversationManager; - } - - public synchronized RuntimeWire lookupCache(EndpointReference callback) { - if (lastCallback != null && callback.getURI().equals(lastCallback.getURI()) && !wireReserved) { - wireReserved = true; - return cachedWire; - } else { - return null; - } - } - - public synchronized void addToCache(EndpointReference callback, RuntimeWire clonedWire) { - ((RuntimeWireImpl)clonedWire).setClonedFrom(this); - lastCallback = callback; - cachedWire = clonedWire; - wireReserved = true; - } - - public synchronized void releaseClonedWire(RuntimeWire wire) { - if (cachedWire == wire) { - wireReserved = false; - } - } - - public synchronized void releaseWire() { - clonedFrom.releaseClonedWire(this); - } - - private void setClonedFrom(RuntimeWireImpl wire) { - clonedFrom = wire; - } - - public EndpointReference2 getEndpointReference(){ - return null; - } -} diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java index 17984b9ef9..205ad6a62c 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java @@ -38,7 +38,7 @@ import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl; +import org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl2; import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl; import org.apache.tuscany.sca.core.assembly.impl.ReferenceParametersImpl; import org.apache.tuscany.sca.core.context.CallableReferenceExt; @@ -118,6 +118,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { this.component = component; this.reference = reference; this.binding = binding; + // FIXME: The SCA Specification is not clear how we should handle multiplicity // for CallableReference if (this.binding == null) { @@ -127,15 +128,10 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { // TODO: TUSCANY-2580: if the refernece doesn't have a binding yet then instead of NPE use a candidate one if its avaialable if (reference.getBindings() != null && reference.getBindings().size() > 0) { this.binding = this.reference.getBindings().get(0); - } else { - this.binding = this.reference.getEndpoints().get(0).getCandidateBindings().get(0); - if (this.reference.getEndpoints().get(0).getInterfaceContract() == null) { - this.reference.getEndpoints().get(0).setInterfaceContract(reference.getInterfaceContract()); - } - } + } } - // TODO - EPR - If not binding specified assume default binding and find the enpoint reference + // TODO - EPR - If no binding specified assume default binding and find the endpoint reference // related to it for (EndpointReference2 endpointReference : this.reference.getEndpointReferences()){ if ((endpointReference.getBinding() != null) && @@ -464,7 +460,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { if (conversation != null) { refParams.setConversationID(conversation.getConversationID()); } - return ((CompositeActivatorImpl)compositeActivator).getCompositeContext().toXML(component, clonedRef); + return ((CompositeActivatorImpl2)compositeActivator).getCompositeContext().toXML(component, clonedRef); } else { return scdl; } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java index a0882c153f..301771d879 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/CallbackReferenceImpl.java @@ -31,7 +31,6 @@ import org.apache.tuscany.sca.assembly.EndpointReference2; import org.apache.tuscany.sca.assembly.OptimizableBinding;
import org.apache.tuscany.sca.core.assembly.impl.EndpointReferenceImpl;
import org.apache.tuscany.sca.core.assembly.impl.RuntimeComponentReferenceImpl;
-import org.apache.tuscany.sca.core.assembly.impl.RuntimeWireImpl;
import org.apache.tuscany.sca.core.assembly.impl.RuntimeWireImpl2;
import org.apache.tuscany.sca.core.context.CompositeContext;
import org.apache.tuscany.sca.core.context.impl.CallableReferenceImpl;
@@ -277,7 +276,7 @@ public class CallbackReferenceImpl<B> extends CallableReferenceImpl<B> { // FIXME: Is this the best way to do this?
final RuntimeWire cbWire = ((RuntimeComponentService) targetService).getRuntimeWires().get(0);
try {
- this.wire = (RuntimeWireImpl) cbWire.clone();
+ this.wire = (RuntimeWireImpl2) cbWire.clone();
} catch (CloneNotSupportedException e) {
throw new IOException(e.toString());
}
diff --git a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java deleted file mode 100644 index f0646e934e..0000000000 --- a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java +++ /dev/null @@ -1,49 +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.endpoint.impl; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.endpointresolver.EndpointResolver; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; - -/** - * The factory for creating endpoint Binding providers - * - * @version $Rev$ $Date$ - */ -public class EndpointResolverFactoryImpl implements EndpointResolverFactory<Endpoint> { - - private ExtensionPointRegistry extensionPoints; - - public EndpointResolverFactoryImpl(ExtensionPointRegistry extensionPoints) { - this.extensionPoints = extensionPoints; - } - - public EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding) { - - return new EndpointResolverImpl(extensionPoints, endpoint); - } - - public Class<Endpoint> getModelType() { - return Endpoint.class; - } -} diff --git a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java b/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java deleted file mode 100644 index b76c4b82f0..0000000000 --- a/java/sca/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java +++ /dev/null @@ -1,112 +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.endpoint.impl; - - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.endpointresolver.EndpointResolver; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint; - - -/** - * The endpoint resolver allows unresolved endpoints to be plumbed into - * the runtime start and message send processing as a hook to late resolution - * of target services - * - * @version $Rev$ $Date$ - */ -public class EndpointResolverImpl implements EndpointResolver { - - private final static Logger logger = Logger.getLogger(EndpointResolverImpl.class.getName()); - - private Endpoint endpoint; - private List<EndpointResolver> endpointResolvers = new ArrayList<EndpointResolver>(); - - public EndpointResolverImpl(ExtensionPointRegistry extensionPoints, - Endpoint endpoint) { - this.endpoint = endpoint; - - EndpointResolverFactoryExtensionPoint resolverFactories = - extensionPoints.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class); - - for (Binding binding : endpoint.getCandidateBindings()){ - EndpointResolverFactory resolverFactory = resolverFactories.getEndpointResolverFactory(binding.getClass()); - - // if the binding in question has a endpoint resolver factory they try and - // create an endpoint resolver - if (resolverFactory != null){ - EndpointResolver resolver = resolverFactory.createEndpointResolver(endpoint, binding); - - if (resolver != null){ - endpointResolvers.add(resolver); - } - } - } - } - - public void start(){ - // do nothing - } - - public void stop(){ - // do nothing - } - - public void resolve() { - if (endpoint.isUnresolved()){ - // Resolve the endpoint binding here - - // first do any general resolution that's required - - // ask the bindings to resolve the endpoint one by one - for (EndpointResolver resolver : endpointResolvers){ - resolver.resolve(); - if (endpoint.isUnresolved() != true){ - break; - } - } - - if (endpoint.isUnresolved()){ - // TODO: TUSCANY-2580: if its still unresolved use the first candidate binding - endpoint.setSourceBinding(endpoint.getCandidateBindings().get(0)); - endpoint.getSourceBinding().setURI(endpoint.getTargetName()); - } - - if (endpoint.isUnresolved() != true){ - // If we have to build the endpoint because we are matching - // intents and policies then we do that now. If the binding - // is just configured by setting its uri we can just do local binding - // configuration here - - // EndpointBuilderImpl.build(endpoint); - } else { - // raise an exception saying the endpoint can't be resolved - } - } - } - -} diff --git a/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory b/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory deleted file mode 100644 index 50e0a930d2..0000000000 --- a/java/sca/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory +++ /dev/null @@ -1,19 +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.
-
-# Implementation class for the binding extension
-org.apache.tuscany.sca.endpoint.impl.EndpointResolverFactoryImpl;model=org.apache.tuscany.sca.assembly.Endpoint
diff --git a/java/sca/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml b/java/sca/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml deleted file mode 100644 index c00df2ef35..0000000000 --- a/java/sca/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml +++ /dev/null @@ -1,26 +0,0 @@ -<?xml version="1.0" encoding="ASCII"?> -<!-- - * 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. ---> -<sca:definitions xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903" - targetNamespace="http://docs.oasis-open.org/ns/opencsa/sca/200903" - xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903" - xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"> - - <sca:bindingType type="sca:binding.sca" mayProvide="" alwaysProvides=""/> - </sca:definitions>
\ No newline at end of file diff --git a/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java b/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java index 388b363e18..7d618d8e92 100644 --- a/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java +++ b/java/sca/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java @@ -29,7 +29,6 @@ import javax.xml.stream.XMLOutputFactory; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; import org.apache.tuscany.sca.assembly.builder.CompositeBuilderExtensionPoint; import org.apache.tuscany.sca.contribution.Contribution; @@ -49,9 +48,6 @@ import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint; import org.apache.tuscany.sca.core.UtilityExtensionPoint; import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; -import org.apache.tuscany.sca.endpoint.impl.EndpointResolverFactoryImpl; -import org.apache.tuscany.sca.endpointresolver.EndpointResolver; -import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.MonitorFactory; import org.junit.Assert; @@ -120,52 +116,7 @@ public class EndpointTestCase { // Create a composite builder compositeBuilder = extensionPoints.getExtensionPoint(CompositeBuilderExtensionPoint.class).getCompositeBuilder("org.apache.tuscany.sca.assembly.builder.CompositeBuilder"); - - // Runtime Init =================== -/* - ContextFactoryExtensionPoint contextFactories = new DefaultContextFactoryExtensionPoint(extensionPoints); - extensionPoints.addExtensionPoint(contextFactories); - - // Create a wire post processor extension point - RuntimeWireProcessorExtensionPoint wireProcessors = - extensionPoints.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); - RuntimeWireProcessor wireProcessor = new ExtensibleWireProcessor(wireProcessors); - - JavaInterfaceFactory javaInterfaceFactory = - extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class).getFactory(JavaInterfaceFactory.class); - RequestContextFactory requestContextFactory = - extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class); - - ConversationManager conversationManager = new ConversationManagerImpl(); - extensionPoints.addExtensionPoint(conversationManager); - - - ScopeRegistry scopeRegistry = new ScopeRegistryImpl(); - ScopeContainerFactory[] factories = - new ScopeContainerFactory[] {new CompositeScopeContainerFactory(), new StatelessScopeContainerFactory(), - new RequestScopeContainerFactory(), - new ConversationalScopeContainerFactory(null), - // new HttpSessionScopeContainer(monitor) - }; - for (ScopeContainerFactory f : factories) { - scopeRegistry.register(f); - } - - compositeActivator =new CompositeActivatorImpl(assemblyFactory, - messageFactory, - javaInterfaceFactory, - scaBindingFactory, - mapper, - scopeRegistry, - extensionPoints.getExtensionPoint(WorkScheduler.class), - wireProcessor, - requestContextFactory, - new DefaultProxyFactoryExtensionPoint(messageFactory, mapper), - extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class), - extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class), - conversationManager); - -*/ + } @@ -185,7 +136,7 @@ public class EndpointTestCase { compositeBuilder.build(composite, null, monitor); ComponentReference ref = (composite.getComponents().get(0).getReferences().get(0)); - +/* TODO - EPR - convert to new endpoint reference Assert.assertEquals(1, ref.getEndpoints().size()); Endpoint endpoint = ref.getEndpoints().get(0); @@ -195,6 +146,7 @@ public class EndpointTestCase { EndpointResolver endpointResolver = factory.createEndpointResolver(endpoint, null); Assert.assertNotNull(endpointResolver); +*/ } catch(Exception ex) { |