diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-24 19:02:28 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-09-24 19:02:28 +0000 |
commit | 8032feb211841df8a32e629896facb1947530415 (patch) | |
tree | d9f6806ba45517ef33864ed1ab5de0c4eb8c6556 /java | |
parent | 71fbc37a1efd6118cb8e49f9e53b5ffbe7e85449 (diff) |
Reformat the code
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@818590 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
29 files changed, 907 insertions, 938 deletions
diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java index 520ab6c695..4e8159b70c 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseBuilderImpl.java @@ -83,7 +83,7 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { this.transformerFactory = transformerFactory; this.interfaceContractMapper = interfaceContractMapper; } - + /** * Construct a builder from the extension point registry * @param registry @@ -458,7 +458,7 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { } } } - + /** * Look to see if any value elements have been set into the property * A bit involved as the value is stored as a DOM Document @@ -466,21 +466,21 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { * @param property the property to be tested * @return true is values are present */ - private boolean isPropertyValueSet(Property property){ + private boolean isPropertyValueSet(Property property) { Document value = (Document)property.getValue(); - - if (value == null){ + + if (value == null) { return false; } - - if (value.getFirstChild() == null){ + + if (value.getFirstChild() == null) { return false; } - - if (value.getFirstChild().getChildNodes().getLength() == 0){ + + if (value.getFirstChild().getChildNodes().getLength() == 0) { return false; } - + return true; } @@ -535,10 +535,10 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { if (!ReferenceConfigurationUtil.isValidMultiplicityOverride(reference.getMultiplicity(), componentReference.getMultiplicity())) { error(monitor, - "ReferenceIncompatibleMultiplicity", - component, - component.getName(), - componentReference.getName()); + "ReferenceIncompatibleMultiplicity", + component, + component.getName(), + componentReference.getName()); } } else { componentReference.setMultiplicity(reference.getMultiplicity()); @@ -549,8 +549,8 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { if (componentReference.getInterfaceContract() != null) { if (interfaceContract != null && !componentReference.getInterfaceContract().equals(reference .getInterfaceContract())) { - if (!interfaceContractMapper.isCompatible(interfaceContract, - componentReference.getInterfaceContract())) { + if (!interfaceContractMapper.isCompatible(interfaceContract, componentReference + .getInterfaceContract())) { error(monitor, "ReferenceIncompatibleComponentInterface", component, @@ -682,7 +682,7 @@ public abstract class BaseBuilderImpl implements CompositeBuilder { return; } contract.setOverridingBindings(false); - + // Only add binding.sca for services // FIXME: The latest OASIS spec only adds binding.sca to services /* diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingURIBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingURIBuilderImpl.java index 762d063256..d0cee1f6fb 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingURIBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingURIBuilderImpl.java @@ -49,7 +49,7 @@ import org.apache.tuscany.sca.monitor.MonitorFactory; * @version $Rev$ $Date$ */ public class BindingURIBuilderImpl { - + private Monitor monitor; public BindingURIBuilderImpl(ExtensionPointRegistry registry) { @@ -58,7 +58,6 @@ public class BindingURIBuilderImpl { monitor = monitorFactory.createMonitor(); } - /** * Called by CompositeBindingURIBuilderImpl * @@ -110,14 +109,14 @@ public class BindingURIBuilderImpl { Definitions definitions, Map<QName, List<String>> defaultBindings, Monitor monitor) throws CompositeBuilderException { - + String parentComponentURI = uri; - + monitor.pushContext("Composite: " + composite.getName().toString()); - try { + try { // Process nested composites recursively for (Component component : composite.getComponents()) { - + // Initialize component URI String componentURI; if (parentComponentURI == null) { @@ -126,37 +125,37 @@ public class BindingURIBuilderImpl { componentURI = URI.create(parentComponentURI + '/').resolve(component.getName()).toString(); } component.setURI(componentURI); - + Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { // Process nested composite - configureBindingURIs((Composite)implementation, componentURI, definitions, defaultBindings, monitor); + configureBindingURIs((Composite)implementation, componentURI, definitions, defaultBindings, monitor); } } - + // Initialize composite service binding URIs List<Service> compositeServices = composite.getServices(); for (Service service : compositeServices) { - + constructBindingNames(service, monitor); - + // Initialize binding names and URIs for (Binding binding : service.getBindings()) { constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings, monitor); } } - + // Initialize component service binding URIs for (Component component : composite.getComponents()) { - + monitor.pushContext("Component: " + component.getName()); - + try { - + for (ComponentService service : component.getServices()) { - + constructBindingNames(service, monitor); - + // Initialize binding names and URIs for (Binding binding : service.getBindings()) { constructBindingURI(component, service, binding, defaultBindings, monitor); @@ -168,7 +167,7 @@ public class BindingURIBuilderImpl { } } finally { monitor.popContext(); - } + } } /** @@ -233,24 +232,20 @@ public class BindingURIBuilderImpl { Binding existed = bindingMap.put(binding.getName(), binding); // Check that multiple bindings do not have the same name if (existed != null && existed != binding) { - if (contract instanceof Service){ - Monitor.error(monitor, - this, - "assembly-validation-messages", - "MultipleBindingsForService", - contract.getName(), - binding.getName()); + if (contract instanceof Service) { + Monitor.error(monitor, this, "assembly-validation-messages", "MultipleBindingsForService", contract + .getName(), binding.getName()); } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "MultipleBindingsForReference", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "MultipleBindingsForReference", contract.getName(), binding.getName()); } } } - + if (contract.getCallback() != null) { bindings = contract.getCallback().getBindings(); bindingMap.clear(); @@ -263,18 +258,18 @@ public class BindingURIBuilderImpl { Binding existed = bindingMap.put(binding.getName(), binding); // Check that multiple bindings do not have the same name if (existed != null && existed != binding) { - if (contract instanceof Service){ - Monitor.error(monitor, - this, - "assembly-validation-messages", - "MultipleBindingsForServiceCallback", + if (contract instanceof Service) { + Monitor.error(monitor, + this, + "assembly-validation-messages", + "MultipleBindingsForServiceCallback", contract.getName(), binding.getName()); } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "MultipleBindingsForReferenceCallback", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "MultipleBindingsForReferenceCallback", contract.getName(), binding.getName()); } @@ -341,9 +336,9 @@ public class BindingURIBuilderImpl { Monitor monitor) throws CompositeBuilderException { try { - + boolean includeBindingName = !service.getName().equals(binding.getName()); - + // calculate the service binding URI URI bindingURI; if (binding.getURI() != null) { @@ -402,13 +397,13 @@ public class BindingURIBuilderImpl { includeBindingName, bindingName)); } catch (URISyntaxException ex) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "URLSyntaxException", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "URLSyntaxException", componentURIString, service.getName(), - binding.getName()); + binding.getName()); } } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java index 18c704340f..6197764f4c 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentBuilderImpl.java @@ -45,7 +45,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.Contract; -import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.assembly.Multiplicity; import org.apache.tuscany.sca.assembly.Property; @@ -75,7 +74,7 @@ import org.xml.sax.InputSource; */ public class ComponentBuilderImpl { private static final Logger logger = Logger.getLogger(ComponentBuilderImpl.class.getName()); - + protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; protected static final String BINDING_SCA = "binding.sca"; protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); @@ -89,7 +88,6 @@ public class ComponentBuilderImpl { private InterfaceContractMapper interfaceContractMapper; private BuilderExtensionPoint builders; - public ComponentBuilderImpl(ExtensionPointRegistry registry) { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); @@ -100,13 +98,13 @@ public class ComponentBuilderImpl { scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); transformerFactory = modelFactories.getFactory(TransformerFactory.class); - + interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); - + builders = registry.getExtensionPoint(BuilderExtensionPoint.class); - } - - public void setComponentTypeBuilder(CompositeComponentTypeBuilderImpl componentTypeBuilder){ + } + + public void setComponentTypeBuilder(CompositeComponentTypeBuilderImpl componentTypeBuilder) { this.componentTypeBuilder = componentTypeBuilder; } @@ -116,13 +114,12 @@ public class ComponentBuilderImpl { * @Param parentComposite the composite that contains the component being configured. Required for property processing * @param component the component to be configured */ - public void configureComponentFromComponentType(Composite parentComposite, - Component component){ - + public void configureComponentFromComponentType(Composite parentComposite, Component component) { + // do any work we need to do before we calculate the component type // for this component. Anything that needs to be pushed down the promotion // hierarchy must be done before we calculate the component type - + // first carry out any implementation specific builder processing Implementation impl = component.getImplementation(); if (impl != null) { @@ -131,79 +128,74 @@ public class ComponentBuilderImpl { builder.build(component, impl, monitor); } } - + // Properties on the composite component type are not affected by the components // that the composite contains. Instead the child components might source // composite level property values. Hence we have to calculate whether the component // type property value should be overridden by this component's property value // before we go ahead and calculate the component type configureProperties(parentComposite, component); - + // create the component type for this component // taking any nested composites into account createComponentType(component); - + // configure services based on the calculated component type configureServices(component); - + // configure services based on the calculated component type configureReferences(component); } - + /** * Use the component type builder to build the component type for * this component. * * @param component */ - private void createComponentType(Component component){ + private void createComponentType(Component component) { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { componentTypeBuilder.createComponentType((Composite)implementation); } } - + /** * Configure this component's services based on the services in its * component type and the configuration from the composite file * * @param component */ - private void configureServices(Component component){ - + private void configureServices(Component component) { + // If the component type has services that are not described in this // component then create services for this component addServicesFromComponentType(component); - + // Connect this component's services to the // services from its component type connectServicesToComponentType(component); - + // look at each component service in turn and calculate its // configuration based on OASIS rules for (ComponentService componentService : component.getServices()) { Service componentTypeService = componentService.getService(); - - if (componentTypeService == null){ + + if (componentTypeService == null) { // raise error? // can be null in some of the assembly-xml unit tests continue; } - + // interface contracts - calculateInterfaceContract(componentService, - componentTypeService); - + calculateInterfaceContract(componentService, componentTypeService); + // bindings - calculateBindings(componentService, - componentTypeService); - - + calculateBindings(componentService, componentTypeService); + // add callback reference model objects - createCallbackReference(component, - componentService); - - + createCallbackReference(component, componentService); + // intents - done later in CompositePolicyBuilder - discuss with RF //calculateIntents(componentService, // componentTypeService); @@ -214,55 +206,49 @@ public class ComponentBuilderImpl { } } - + /** * Configure this component's references based on the references in its * component type and the configuration from the composite file * * @param component */ - private void configureReferences(Component component){ - + private void configureReferences(Component component) { + // If the component type has references that are not described in this // component then create references for this component addReferencesFromComponentType(component); - + // Connect this component's references to the // references from its component type connectReferencesToComponentType(component); - + // look at each component reference in turn and calculate its // configuration based on OASIS rules for (ComponentReference componentReference : component.getReferences()) { Reference componentTypeReference = componentReference.getReference(); - - if (componentTypeReference == null){ + + if (componentTypeReference == null) { // raise error? // can be null in some of the assembly-xml unit tests continue; } - + // reference multiplicity - reconcileReferenceMultiplicity(component, - componentReference, - componentTypeReference); + reconcileReferenceMultiplicity(component, componentReference, componentTypeReference); // interface contracts - calculateInterfaceContract(componentReference, - componentTypeReference); - + calculateInterfaceContract(componentReference, componentTypeReference); + // bindings // We don't have to do anything with reference bindings. You've either // specified one or you haven't //calculateBindings(componentService, // componentTypeService); - - + // add callback service model objects - createCallbackService(component, - componentReference); - - + createCallbackService(component, componentReference); + // intents - done later in CompositePolicyBuilder - discuss with RF //calculateIntents(componentService, // componentTypeService); @@ -270,7 +256,7 @@ public class ComponentBuilderImpl { // policy sets - done later in CompositePolicyBuilder - discuss with RF // calculatePolicySets(componentService, // componentTypeService); - + // Propagate autowire setting from the component down the structural // hierarchy if (componentReference.getAutowire() == null) { @@ -283,49 +269,44 @@ public class ComponentBuilderImpl { } } - } - + } + /** * Configure this component's properties based on the properties in its * component type and the configuration from the composite file * * @param component */ - private void configureProperties(Composite parentComposite, Component component){ + private void configureProperties(Composite parentComposite, Component component) { // If the component type has properties that are not described in this // component then create properties for this component addPropertiesFromComponentType(component); - + // Connect this component's properties to the // properties from its component type connectReferencesToComponentType(component); - + // Reconcile component properties and their component type properties for (ComponentProperty componentProperty : component.getProperties()) { - reconcileComponentPropertyWithComponentType(component, - componentProperty); - + reconcileComponentPropertyWithComponentType(component, componentProperty); + // configure the property value based on the @source attribute // At the moment this is done in the parent composite component // type calculation a - processPropertySourceAttribute(parentComposite, - component, - componentProperty); - + processPropertySourceAttribute(parentComposite, component, componentProperty); + // configure the property value based on the @file attribute - processPropertyFileAttribute(component, - componentProperty); + processPropertyFileAttribute(component, componentProperty); } } - - private void addServicesFromComponentType(Component component){ - + + private void addServicesFromComponentType(Component component) { + // Create a component service for each service if (component.getImplementation() != null) { for (Service service : component.getImplementation().getServices()) { - ComponentService componentService = - (ComponentService)component.getService(service.getName()); - + ComponentService componentService = (ComponentService)component.getService(service.getName()); + // if the component doesn't have a service with the same name as the // component type service then create one if (componentService == null) { @@ -337,16 +318,15 @@ public class ComponentBuilderImpl { } } } - } - - private void addReferencesFromComponentType(Component component){ - + } + + private void addReferencesFromComponentType(Component component) { + // Create a component reference for each reference if (component.getImplementation() != null) { for (Reference reference : component.getImplementation().getReferences()) { - ComponentReference componentReference = - (ComponentReference)component.getReference(reference.getName()); - + ComponentReference componentReference = (ComponentReference)component.getReference(reference.getName()); + // if the component doesn't have a reference with the same name as the // component type reference then create one if (componentReference == null) { @@ -358,16 +338,15 @@ public class ComponentBuilderImpl { } } } - } - - private void addPropertiesFromComponentType(Component component){ - + } + + private void addPropertiesFromComponentType(Component component) { + // Create component property for each property if (component.getImplementation() != null) { for (Property property : component.getImplementation().getProperties()) { - ComponentProperty componentProperty = - (ComponentProperty)component.getProperty(property.getName()); - + ComponentProperty componentProperty = (ComponentProperty)component.getProperty(property.getName()); + // if the component doesn't have a property with the same name as // the component type property then create one if (componentProperty == null) { @@ -384,113 +363,111 @@ public class ComponentBuilderImpl { } } } - - private void connectServicesToComponentType(Component component){ - + + private void connectServicesToComponentType(Component component) { + // Connect each component service to the corresponding component type service for (ComponentService componentService : component.getServices()) { if (componentService.getService() != null || componentService.isForCallback()) { continue; } - - if (component.getImplementation() == null){ + + if (component.getImplementation() == null) { // is null in some of our basic unit tests continue; } - + Service service = component.getImplementation().getService(componentService.getName()); if (service != null) { componentService.setService(service); } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ServiceNotFoundForComponentService", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "ServiceNotFoundForComponentService", component.getName(), componentService.getName()); } } } - - private void connectReferencesToComponentType(Component component){ - + + private void connectReferencesToComponentType(Component component) { + // Connect each component reference to the corresponding component type reference for (ComponentReference componentReference : component.getReferences()) { if (componentReference.getReference() != null || componentReference.isForCallback()) { continue; } - - if (component.getImplementation() == null){ + + if (component.getImplementation() == null) { // is null in some of our basic unit tests continue; - } - + } + Reference reference = component.getImplementation().getReference(componentReference.getName()); if (reference != null) { componentReference.setReference(reference); } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceNotFoundForComponentReference", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "ReferenceNotFoundForComponentReference", component.getName(), componentReference.getName()); } - } - } - - private void connectPropertiesToComponentType(Component component){ + } + } + + private void connectPropertiesToComponentType(Component component) { // Connect each component property to the corresponding component type property for (ComponentProperty componentProperty : component.getProperties()) { Property property = component.getImplementation().getProperty(componentProperty.getName()); if (property != null) { componentProperty.setProperty(property); } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyNotFound", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "PropertyNotFound", component.getName(), componentProperty.getName()); } } } - + private void reconcileReferenceMultiplicity(Component component, Reference componentReference, - Reference componentTypeReference){ + Reference componentTypeReference) { if (componentReference.getMultiplicity() != null) { - if (!isValidMultiplicityOverride(componentTypeReference.getMultiplicity(), - componentReference.getMultiplicity())) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceIncompatibleMultiplicity", - component.getName(), - componentReference.getName()); + if (!isValidMultiplicityOverride(componentTypeReference.getMultiplicity(), componentReference + .getMultiplicity())) { + Monitor.error(monitor, + this, + "assembly-validation-messages", + "ReferenceIncompatibleMultiplicity", + component.getName(), + componentReference.getName()); } } else { componentReference.setMultiplicity(componentTypeReference.getMultiplicity()); } } - - private void reconcileComponentPropertyWithComponentType(Component component, - ComponentProperty componentProperty){ + + private void reconcileComponentPropertyWithComponentType(Component component, ComponentProperty componentProperty) { Property componentTypeProperty = componentProperty.getProperty(); if (componentTypeProperty != null) { // Check that a component property does not override the // mustSupply attribute - if (!componentTypeProperty.isMustSupply() && - componentProperty.isMustSupply()) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyMustSupplyIncompatible", + if (!componentTypeProperty.isMustSupply() && componentProperty.isMustSupply()) { + Monitor.error(monitor, + this, + "assembly-validation-messages", + "PropertyMustSupplyIncompatible", component.getName(), - componentProperty.getName()); + componentProperty.getName()); } // Default to the mustSupply attribute specified on the property @@ -508,26 +485,16 @@ public class ComponentBuilderImpl { } // Check that a value is supplied - if (!isPropertyValueSet(componentProperty) && - componentTypeProperty.isMustSupply()) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyMustSupplyNull", - component.getName(), - componentProperty.getName()); + if (!isPropertyValueSet(componentProperty) && componentTypeProperty.isMustSupply()) { + Monitor.error(monitor, this, "assembly-validation-messages", "PropertyMustSupplyNull", component + .getName(), componentProperty.getName()); } // Check that a component property does not override the // many attribute - if (!componentTypeProperty.isMany() && - componentProperty.isMany()) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyOverrideManyAttribute", - component.getName(), - componentProperty.getName()); + if (!componentTypeProperty.isMany() && componentProperty.isMany()) { + Monitor.error(monitor, this, "assembly-validation-messages", "PropertyOverrideManyAttribute", component + .getName(), componentProperty.getName()); } // Default to the many attribute defined on the property @@ -542,18 +509,13 @@ public class ComponentBuilderImpl { } // Check that a type or element are specified - if (componentProperty.getXSDElement() == null && - componentProperty.getXSDType() == null) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "NoTypeForComponentProperty", - component.getName(), - componentProperty.getName()); + if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) { + Monitor.error(monitor, this, "assembly-validation-messages", "NoTypeForComponentProperty", component + .getName(), componentProperty.getName()); } } } - + /** * If the property has a source attribute use this to retrieve the value from a * property in the parent composite @@ -563,11 +525,11 @@ public class ComponentBuilderImpl { * @param component * @param componentProperty */ - private void processPropertySourceAttribute(Composite parentComposite, + private void processPropertySourceAttribute(Composite parentComposite, Component component, - ComponentProperty componentProperty){ + ComponentProperty componentProperty) { String source = componentProperty.getSource(); - + if (source != null) { // $<name>/... int index = source.indexOf('/'); @@ -580,48 +542,49 @@ public class ComponentBuilderImpl { String name = source.substring(1, index); Property compositeProp = parentComposite.getProperty(name); if (compositeProp == null) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertySourceNotFound", - source, - componentProperty.getName(), - component.getName()); + Monitor.error(monitor, + this, + "assembly-validation-messages", + "PropertySourceNotFound", + source, + componentProperty.getName(), + component.getName()); } - + Document compositePropDefValues = (Document)compositeProp.getValue(); - + try { // FIXME: How to deal with namespaces? - Document node = evaluateXPath(compositePropDefValues, - componentProperty.getSourceXPathExpression(), - documentBuilderFactory); - + Document node = + evaluateXPath(compositePropDefValues, + componentProperty.getSourceXPathExpression(), + documentBuilderFactory); + if (node != null) { componentProperty.setValue(node); } - } catch (Exception ex){ - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertySourceXpathInvalid", - source, - componentProperty.getName(), - component.getName(), - ex.toString()); + } catch (Exception ex) { + Monitor.error(monitor, + this, + "assembly-validation-messages", + "PropertySourceXpathInvalid", + source, + componentProperty.getName(), + component.getName(), + ex.toString()); } } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertySourceValueInvalid", - source, - componentProperty.getName(), - component.getName()); + Monitor.error(monitor, + this, + "assembly-validation-messages", + "PropertySourceValueInvalid", + source, + componentProperty.getName(), + component.getName()); } } - } - + } + /** * If the property has a file attribute use this to retrieve the value from a * local file @@ -630,11 +593,10 @@ public class ComponentBuilderImpl { * @param parentCompoent the composite that contains the component * @param component */ - private void processPropertyFileAttribute(Component component, - ComponentProperty componentProperty){ + private void processPropertyFileAttribute(Component component, ComponentProperty componentProperty) { String file = componentProperty.getFile(); if (file != null) { - try{ + try { URI uri = URI.create(file); // URI resolution for relative URIs is done when the composite is resolved. URL url = uri.toURL(); @@ -643,14 +605,14 @@ public class ComponentBuilderImpl { InputStream is = null; try { is = connection.getInputStream(); - + Source streamSource = new SAXSource(new InputSource(is)); DOMResult result = new DOMResult(); javax.xml.transform.Transformer transformer = transformerFactory.newTransformer(); transformer.transform(streamSource, result); - + Document document = (Document)result.getNode(); - + // TUSCANY-2377, Add a fake value element so it's consistent with // the DOM tree loaded from inside SCDL Element root = document.createElementNS(null, "value"); @@ -662,20 +624,20 @@ public class ComponentBuilderImpl { is.close(); } } - } catch (Exception ex){ - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PropertyFileValueInvalid", - file, - componentProperty.getName(), - component.getName(), - ex.toString()); + } catch (Exception ex) { + Monitor.error(monitor, + this, + "assembly-validation-messages", + "PropertyFileValueInvalid", + file, + componentProperty.getName(), + component.getName(), + ex.toString()); } } - + } - + /** * Evaluate an XPath expression against a Property value, returning the result as a Property value * @param node - the document root element of a Property value @@ -687,8 +649,8 @@ public class ComponentBuilderImpl { */ private Document evaluateXPath(Document node, XPathExpression expression, - DocumentBuilderFactory documentBuilderFactory) - throws XPathExpressionException, ParserConfigurationException { + DocumentBuilderFactory documentBuilderFactory) throws XPathExpressionException, + ParserConfigurationException { // The document element is a <sca:property/> element Node property = node.getDocumentElement(); @@ -719,8 +681,8 @@ public class ComponentBuilderImpl { return document; } - } - + } + /** * Create a callback reference for a component service * @@ -728,12 +690,12 @@ public class ComponentBuilderImpl { * @param service */ private void createCallbackReference(Component component, ComponentService service) { - + // if the service has a callback interface create a reference // to represent the callback if (service.getInterfaceContract() != null && // can be null in unit tests - service.getInterfaceContract().getCallbackInterface() != null) { - + service.getInterfaceContract().getCallbackInterface() != null) { + ComponentReference callbackReference = assemblyFactory.createComponentReference(); callbackReference.setForCallback(true); callbackReference.setName(service.getName()); @@ -747,14 +709,15 @@ public class ComponentBuilderImpl { } Service implService = service.getService(); if (implService != null) { - + // If the implementation service is a CompositeService, ensure that the Reference that is // created is a CompositeReference, otherwise create a Reference Reference implReference; if (implService instanceof CompositeService) { CompositeReference implCompReference = assemblyFactory.createCompositeReference(); // Set the promoted component from the promoted component of the composite service - implCompReference.getPromotedComponents().add(((CompositeService)implService).getPromotedComponent()); + implCompReference.getPromotedComponents().add(((CompositeService)implService) + .getPromotedComponent()); // Set the promoted service ComponentReference promotedReference = assemblyFactory.createComponentReference(); String promotedRefName = @@ -768,11 +731,11 @@ public class ComponentBuilderImpl { Implementation implementation = component.getImplementation(); if (implementation != null && implementation instanceof Composite) { ((Composite)implementation).getReferences().add(implCompReference); - } + } } else { implReference = assemblyFactory.createReference(); - } - + } + implReference.setName(implService.getName()); try { InterfaceContract implContract = (InterfaceContract)implService.getInterfaceContract().clone(); @@ -785,38 +748,37 @@ public class ComponentBuilderImpl { callbackReference.setReference(implReference); } component.getReferences().add(callbackReference); - + // Set the bindings of the callback reference if (callbackReference.getBindings().isEmpty()) { // If there are specific callback bindings set in the SCDL service // callback element then use them - if (service.getCallback() != null && - service.getCallback().getBindings().size() > 0 ) { + if (service.getCallback() != null && service.getCallback().getBindings().size() > 0) { callbackReference.getBindings().addAll(service.getCallback().getBindings()); } else { // otherwise create a default binding which // will cause the EPR for this reference to be // marked as EndpointReference.NOT_CONFIGURED createSCABinding(callbackReference, null); - + // TODO - should really use the forward binding here but // awaiting OASIS decision on what's going to // happen with callbacks } - } - service.setCallbackReference(callbackReference); + } + service.setCallbackReference(callbackReference); } - } - + } + /** * Create a callback service for a component reference * * @param component * @param service */ - private void createCallbackService(Component component, ComponentReference reference) { + private void createCallbackService(Component component, ComponentReference reference) { if (reference.getInterfaceContract() != null && // can be null in unit tests - reference.getInterfaceContract().getCallbackInterface() != null) { + reference.getInterfaceContract().getCallbackInterface() != null) { ComponentService componentService = assemblyFactory.createComponentService(); componentService.setForCallback(true); componentService.setName(reference.getName()); @@ -839,12 +801,13 @@ public class ComponentBuilderImpl { // one component reference - and there must be a separate composite callback service for each of these component // references // Set the promoted component from the promoted component of the composite reference - implCompService - .setPromotedComponent(((CompositeReference)implReference).getPromotedComponents().get(0)); + implCompService.setPromotedComponent(((CompositeReference)implReference).getPromotedComponents() + .get(0)); implCompService.setForCallback(true); // Set the promoted service ComponentService promotedService = assemblyFactory.createComponentService(); - promotedService.setName(((CompositeReference)implReference).getPromotedReferences().get(0).getName()); + promotedService.setName(((CompositeReference)implReference).getPromotedReferences().get(0) + .getName()); promotedService.setUnresolved(true); promotedService.setForCallback(true); implCompService.setPromotedService(promotedService); @@ -871,26 +834,25 @@ public class ComponentBuilderImpl { componentService.setService(implService); } component.getServices().add(componentService); - + // configure bindings for the callback service if (componentService.getBindings().isEmpty()) { - if (reference.getCallback() != null && - reference.getCallback().getBindings().size() > 0) { + if (reference.getCallback() != null && reference.getCallback().getBindings().size() > 0) { // set bindings of the callback service based on the information provided in // SCDL reference callback element componentService.getBindings().addAll(reference.getCallback().getBindings()); - } else if (reference.getBindings().size() > 0){ + } else if (reference.getBindings().size() > 0) { // use any bindings explicitly declared on the forward reference - for (Binding binding : reference.getBindings()){ + for (Binding binding : reference.getBindings()) { try { Binding clonedBinding = (Binding)binding.clone(); // binding uri will be calculated during runtime build clonedBinding.setURI(null); componentService.getBindings().add(clonedBinding); - } catch (CloneNotSupportedException ex){ - + } catch (CloneNotSupportedException ex) { + } - } + } } else { // TODO - should use the binding resolved from the service but // waiting for OASIS to decide what to do about callbacks @@ -898,11 +860,11 @@ public class ComponentBuilderImpl { createSCABinding(componentService, null); } } - + reference.setCallbackService(componentService); } } - + /** * Create a default SCA binding in the case that no binding * is specified by the user @@ -924,8 +886,8 @@ public class ComponentBuilderImpl { contract.getBindings().add(scaBinding); contract.setOverridingBindings(false); - } - + } + /** * Look to see if any value elements have been set into the property * A bit involved as the value is stored as a DOM Document @@ -933,30 +895,30 @@ public class ComponentBuilderImpl { * @param property the property to be tested * @return true is values are present */ - private boolean isPropertyValueSet(Property property){ + private boolean isPropertyValueSet(Property property) { Document value = (Document)property.getValue(); - - if (value == null){ + + if (value == null) { return false; } - - if (value.getFirstChild() == null){ + + if (value.getFirstChild() == null) { return false; } - - if (value.getFirstChild().getChildNodes().getLength() == 0){ + + if (value.getFirstChild().getChildNodes().getLength() == 0) { return false; } - + return true; - } - - private boolean isValidMultiplicityOverride(Multiplicity definedMul, - Multiplicity overridenMul) { + } + + private boolean isValidMultiplicityOverride(Multiplicity definedMul, Multiplicity overridenMul) { if (definedMul != overridenMul) { switch (definedMul) { case ZERO_N: - return overridenMul == Multiplicity.ZERO_ONE || overridenMul == Multiplicity.ONE_ONE || overridenMul == Multiplicity.ONE_N; + return overridenMul == Multiplicity.ZERO_ONE || overridenMul == Multiplicity.ONE_ONE + || overridenMul == Multiplicity.ONE_N; case ONE_N: return overridenMul == Multiplicity.ONE_ONE; case ZERO_ONE: @@ -967,42 +929,40 @@ public class ComponentBuilderImpl { } else { return true; } - } - + } + /** * The following methods implement rules that the OASIS specification defined explicitly * to control how configuration from a component type is inherited by a component */ - + /** * OASIS RULE: Interface contract from higher in the implementation hierarchy takes precedence * * @param topContract the top contract * @param bottomContract the bottom contract - */ - private void calculateInterfaceContract(Contract topContract, - Contract bottomContract) { - + */ + private void calculateInterfaceContract(Contract topContract, Contract bottomContract) { + // Use the interface contract from the bottom level contract if // none is specified on the top level contract InterfaceContract topInterfaceContract = topContract.getInterfaceContract(); InterfaceContract bottomInterfaceContract = bottomContract.getInterfaceContract(); - + if (topInterfaceContract == null) { topContract.setInterfaceContract(bottomInterfaceContract); } else if (bottomInterfaceContract != null) { // Check that the top and bottom interface contracts are compatible - boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract, - bottomInterfaceContract); + boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract, bottomInterfaceContract); if (!isCompatible) { if (topContract instanceof Reference) { - Monitor.error(monitor, + Monitor.error(monitor, this, "assembly-validation-messages", "ReferenceInterfaceNotSubSet", topContract.getName()); } else { - Monitor.error(monitor, + Monitor.error(monitor, this, "assembly-validation-messages", "ServiceInterfaceNotSubSet", @@ -1010,21 +970,20 @@ public class ComponentBuilderImpl { } } } - } - + } + /** * OASIS RULE: Bindings from higher in the hierarchy take precedence * * @param componentService the top service * @param componentTypeService the bottom service - */ - private void calculateBindings(Service componentService, - Service componentTypeService){ + */ + private void calculateBindings(Service componentService, Service componentTypeService) { // forward bindings if (componentService.getBindings().isEmpty()) { componentService.getBindings().addAll(componentTypeService.getBindings()); } - + if (componentService.getBindings().isEmpty()) { createSCABinding(componentService, null); } @@ -1039,7 +998,7 @@ public class ComponentBuilderImpl { } else if (componentService.getCallback().getBindings().isEmpty() && componentTypeService.getCallback() != null) { componentService.getCallback().getBindings().addAll(componentTypeService.getCallback().getBindings()); } - - } + + } } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java index 9d697a67a7..02a6fb8037 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java @@ -58,7 +58,8 @@ public class ComponentConfigurationBuilderImpl extends BaseBuilderImpl implement return "org.apache.tuscany.sca.assembly.builder.ComponentConfigurationBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { configureComponents(composite, definitions, monitor); return composite; } @@ -83,15 +84,15 @@ public class ComponentConfigurationBuilderImpl extends BaseBuilderImpl implement * @param problems */ private void configureComponents(Composite composite, String uri, Definitions definitions, Monitor monitor) { - String parentURI = uri; - + String parentURI = uri; + monitor.pushContext("Composite: " + composite.getName().toString()); - + try { - + // Process nested composites recursively for (Component component : composite.getComponents()) { - + // Initialize component URI String componentURI; if (parentURI == null) { @@ -100,49 +101,49 @@ public class ComponentConfigurationBuilderImpl extends BaseBuilderImpl implement componentURI = URI.create(parentURI + '/').resolve(component.getName()).toString(); } component.setURI(componentURI); - + Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - // Process nested composite - configureComponents((Composite)implementation, componentURI, definitions, monitor); + // Process nested composite + configureComponents((Composite)implementation, componentURI, definitions, monitor); } } // end for - + // Initialize service bindings List<Service> compositeServices = composite.getServices(); for (Service service : compositeServices) { // Set default binding names - + // Create default SCA binding attachSCABinding(service, definitions); } - + // Initialize reference bindings for (Reference reference : composite.getReferences()) { // Create default SCA binding attachSCABinding(reference, definitions); } - + // Initialize all component services and references Map<String, Component> components = new HashMap<String, Component>(); for (Component component : composite.getComponents()) { - - + monitor.pushContext("Component: " + component.getName()); - + try { - // Index all components and check for duplicates - if (components.containsKey(component.getName())) { - error(monitor, "DuplicateComponentName", component, composite.getName().toString(), component.getName()); - } else { - components.put(component.getName(), component); - } - - // Propagate the autowire flag from the composite to components - if (component.getAutowire() == null) { - component.setAutowire(composite.getAutowire()); - } - + // Index all components and check for duplicates + if (components.containsKey(component.getName())) { + error(monitor, "DuplicateComponentName", component, composite.getName().toString(), component + .getName()); + } else { + components.put(component.getName(), component); + } + + // Propagate the autowire flag from the composite to components + if (component.getAutowire() == null) { + component.setAutowire(composite.getAutowire()); + } + Implementation impl = component.getImplementation(); if (impl != null) { ImplementationBuilder builder = builders.getImplementationBuilder(impl.getClass()); @@ -150,58 +151,62 @@ public class ComponentConfigurationBuilderImpl extends BaseBuilderImpl implement builder.build(component, impl, monitor); } } - - // Index implementation properties, services and references - Map<String, Service> services = new HashMap<String, Service>(); - Map<String, Reference> references = new HashMap<String, Reference>(); - Map<String, Property> properties = new HashMap<String, Property>(); - indexImplementationPropertiesServicesAndReferences(component, services, references, properties, monitor); - - // Index component services, references and properties - // Also check for duplicates - Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); - Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); - Map<String, ComponentProperty> componentProperties = new HashMap<String, ComponentProperty>(); - indexComponentPropertiesServicesAndReferences(component, - componentServices, - componentReferences, - componentProperties, - monitor); - - // Reconcile component services/references/properties and - // implementation services/references and create component - // services/references/properties for the services/references - // declared by the implementation - reconcileServices(component, services, componentServices, monitor); - reconcileReferences(component, references, componentReferences, monitor); - reconcileProperties(component, properties, componentProperties, monitor); - - // Configure or create callback services for component's references - // with callbacks - configureCallbackServices(component, componentServices); - - // Configure or create callback references for component's services - // with callbacks - configureCallbackReferences(component, componentReferences); - - // Initialize service bindings - for (ComponentService componentService : component.getServices()) { - - // Create default SCA binding - attachSCABinding(componentService, definitions); - } - - // Initialize reference bindings - for (ComponentReference componentReference : component.getReferences()) { - - // Create default SCA binding - attachSCABinding(componentReference, definitions); - } + + // Index implementation properties, services and references + Map<String, Service> services = new HashMap<String, Service>(); + Map<String, Reference> references = new HashMap<String, Reference>(); + Map<String, Property> properties = new HashMap<String, Property>(); + indexImplementationPropertiesServicesAndReferences(component, + services, + references, + properties, + monitor); + + // Index component services, references and properties + // Also check for duplicates + Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); + Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); + Map<String, ComponentProperty> componentProperties = new HashMap<String, ComponentProperty>(); + indexComponentPropertiesServicesAndReferences(component, + componentServices, + componentReferences, + componentProperties, + monitor); + + // Reconcile component services/references/properties and + // implementation services/references and create component + // services/references/properties for the services/references + // declared by the implementation + reconcileServices(component, services, componentServices, monitor); + reconcileReferences(component, references, componentReferences, monitor); + reconcileProperties(component, properties, componentProperties, monitor); + + // Configure or create callback services for component's references + // with callbacks + configureCallbackServices(component, componentServices); + + // Configure or create callback references for component's services + // with callbacks + configureCallbackReferences(component, componentReferences); + + // Initialize service bindings + for (ComponentService componentService : component.getServices()) { + + // Create default SCA binding + attachSCABinding(componentService, definitions); + } + + // Initialize reference bindings + for (ComponentReference componentReference : component.getReferences()) { + + // Create default SCA binding + attachSCABinding(componentReference, definitions); + } } finally { monitor.popContext(); } } - + } finally { monitor.popContext(); } // end try diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java index 527a66b780..ae0bcaac69 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java @@ -45,8 +45,9 @@ public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder { public ComponentReferenceBindingBuilderImpl(ExtensionPointRegistry registry) { this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); } - - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { buildReferenceBindings(composite, monitor); return composite; } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java index cb73848a51..544e8ca8c6 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceEndpointReferenceBuilderImpl.java @@ -70,7 +70,8 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI * * @param composite */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { this.monitor = monitor; // process component services @@ -85,58 +86,67 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI // 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()) { monitor.pushContext("Component: " + component.getName()); - + try { if (useNew) { for (ComponentReference reference : component.getReferences()) { - createReferenceEndpointReferences2(composite, component, reference, components, componentServices); + createReferenceEndpointReferences2(composite, + component, + reference, + components, + componentServices); } // end for } - + // recurse for composite implementations Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { processComponentReferences((Composite)implementation); } - + // create endpoint references to represent the component reference for (ComponentReference reference : component.getReferences()) { - + if (!useNew) { - createReferenceEndpointReferences(composite, component, reference, components, componentServices); + createReferenceEndpointReferences(composite, + component, + reference, + components, + componentServices); } // end if - + // fix up links between endpoints and endpoint references that represent callbacks for (ComponentService service : component.getServices()) { if ((service.getInterfaceContract() != null) && (service.getInterfaceContract() .getCallbackInterface() != null)) { if (reference.getName().equals(service.getName())) { for (Endpoint endpoint : service.getEndpoints()) { - endpoint.getCallbackEndpointReferences().addAll(reference.getEndpointReferences()); + endpoint.getCallbackEndpointReferences().addAll(reference + .getEndpointReferences()); } break; } // end if } // end if } // end for } // end for - + // Validate that references are wired or promoted, according // to their multiplicity validateReferenceMultiplicity(composite, component); - + } finally { monitor.popContext(); } } // end for - + } finally { monitor.popContext(); } @@ -148,9 +158,9 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI ComponentReference reference, Map<String, Component> components, Map<String, ComponentService> componentServices) { - + monitor.pushContext("Reference: " + reference.getName()); - + // Get reference targets List<ComponentService> refTargets = getReferenceTargets(reference); if (reference.getAutowire() == Boolean.TRUE && reference.getTargets().isEmpty()) { @@ -159,11 +169,11 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI // autowired reference Multiplicity multiplicity = reference.getMultiplicity(); for (Component targetComponent : composite.getComponents()) { - + // Tuscany specific selection of the first autowire reference // when there are more than one (ASM_60025) - if ((multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) && - (reference.getEndpointReferences().size() != 0) ) { + if ((multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) && (reference + .getEndpointReferences().size() != 0)) { break; } @@ -190,10 +200,10 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { if (reference.getEndpointReferences().size() == 0) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "NoComponentReferenceTarget", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "NoComponentReferenceTarget", reference.getName()); } } @@ -214,7 +224,7 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI String targetName = getComponentServiceName(target.getName()); String bindingName = getBindingName(target.getName()); ComponentService targetComponentService = componentServices.get(targetName); - + Component targetComponent = getComponentFromTargetName(components, targetName); if (targetComponentService != null) { @@ -222,52 +232,53 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - if (bindingName != null){ + if (bindingName != null) { // the user has selected a binding as part of the target name Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()){ - if (tmp.getName().equals(bindingName)){ + + for (Binding tmp : targetComponentService.getBindings()) { + if (tmp.getName().equals(bindingName)) { targetBinding = tmp; continue; } } - - if (targetBinding != null){ + + if (targetBinding != null) { EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, targetBinding, true)); + endpointRef.setTargetEndpoint(createEndpoint(targetComponent, + targetComponentService, + targetBinding, + true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); // relying on the registry here to resolve the real endpoint reference.getEndpointReferences().add(endpointRef); - + } else { EndpointReference endpointRef = createEndpointRef(component, reference, true); endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); endpointRef.setRemote(true); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); reference.getEndpointReferences().add(endpointRef); - warning(monitor, - "ComponentReferenceTargetNotFound", - composite, - composite.getName().toString(), - targetName); + warning(monitor, "ComponentReferenceTargetNotFound", composite, composite.getName() + .toString(), targetName); } - + } else { // the user hasn't selected a binding as part of the target name EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); + endpointRef + .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); reference.getEndpointReferences().add(endpointRef); } } else { error(monitor, - "ReferenceIncompatibleInterface", - composite, - composite.getName().toString(), - component.getName() + "." + reference.getName(), - targetName); + "ReferenceIncompatibleInterface", + composite, + composite.getName().toString(), + component.getName() + "." + reference.getName(), + targetName); } } else { // add an unresolved endpoint reference with an unresolved endpoint to go with it @@ -324,7 +335,7 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI if (uri.startsWith("/")) { uri = uri.substring(1); } - + String targetName = getComponentServiceName(uri); String bindingName = getBindingName(uri); @@ -341,42 +352,44 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI // a superset of the component reference interface if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - if (bindingName != null){ + if (bindingName != null) { // the user has selected a binding as part of the target name Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()){ - if (tmp.getName().equals(bindingName)){ + + for (Binding tmp : targetComponentService.getBindings()) { + if (tmp.getName().equals(bindingName)) { targetBinding = tmp; continue; } } - - if (targetBinding != null){ + + if (targetBinding != null) { EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, targetBinding, true)); + endpointRef.setTargetEndpoint(createEndpoint(targetComponent, + targetComponentService, + targetBinding, + true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); // relying on the registry here to resolve the real endpoint reference.getEndpointReferences().add(endpointRef); - + } else { EndpointReference endpointRef = createEndpointRef(component, reference, true); endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); endpointRef.setRemote(true); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); reference.getEndpointReferences().add(endpointRef); - warning(monitor, - "ComponentReferenceTargetNotFound", - composite, - composite.getName().toString(), - targetName); + warning(monitor, "ComponentReferenceTargetNotFound", composite, composite.getName() + .toString(), targetName); } - + } else { // create endpoint reference with dummy endpoint which will be replaced when policies // are matched and bindings are configured later - EndpointReference endpointRef = createEndpointRef(component, reference, binding, null, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); + EndpointReference endpointRef = + createEndpointRef(component, reference, binding, null, false); + endpointRef + .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); reference.getEndpointReferences().add(endpointRef); } @@ -402,12 +415,12 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI } // end if } } - + monitor.popContext(); - + } // end method - - private void validateReferenceMultiplicity(Composite composite, Component component){ + + private void validateReferenceMultiplicity(Composite composite, Component component) { for (ComponentReference componentReference : component.getReferences()) { if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), componentReference.getEndpointReferences())) { @@ -430,25 +443,25 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI composite.getName().toString(), componentReference.getName()); } - } else { + } else { // no error if reference is autowire and more targets // than multiplicity have been found - if (componentReference.getAutowire() == Boolean.TRUE){ + if (componentReference.getAutowire() == Boolean.TRUE) { break; } - + // TUSCANY-3132 first example of updated error handling Monitor.error(monitor, this, "assembly-validation-messages", - "TooManyReferenceTargets", - componentReference.getName()); + "TooManyReferenceTargets", + componentReference.getName()); } } } } - + /** * Create Endpoint References for a component reference inside a given composite * @param composite - the composite @@ -982,7 +995,7 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI } // end if return theTargets; } // end method getReferenceTargets - + /** * Target names can take the form * component/service/binding @@ -993,14 +1006,14 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI */ private String getComponentServiceName(String targetName) { String[] parts = targetName.split("/"); - - if (parts.length > 1){ + + if (parts.length > 1) { return parts[0] + "/" + parts[1]; } else { return parts[0]; } - } - + } + /** * Target names can take the form * component/service/binding @@ -1012,13 +1025,13 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI */ private String getBindingName(String targetName) { String[] parts = targetName.split("/"); - - if (parts.length == 3){ + + if (parts.length == 3) { return parts[2]; } else { return null; } - } + } /** * Helper method that finds the Component given a target name @@ -1086,7 +1099,7 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI endpoint.setUnresolved(unresolved); return endpoint; } // end method createEndpoint - + /** * Helper method to create an endpoint * @param component @@ -1170,26 +1183,27 @@ public class ComponentReferenceEndpointReferenceBuilderImpl extends BaseBuilderI * declares a single target service, the reference is wired only to * the single service identified by the <wire/> element */ - private void setSingleAutoWireTarget(ComponentReference reference) { - if (reference.getEndpointReferences().size() > 1 && reference.getBindings() != null && reference.getBindings().size() == 1) { - String uri = reference.getBindings().get(0).getURI(); - if (uri != null) { - if (uri.indexOf('/') > -1) { - // TODO: must be a way to avoid this fiddling - int i = uri.indexOf('/'); - String c = uri.substring(0, i); - String s = uri.substring(i+1); - uri = c + "#service(" + s + ")"; - } - for (EndpointReference er : reference.getEndpointReferences()) { - if (er.getTargetEndpoint() != null && uri.equals(er.getTargetEndpoint().getURI())) { - reference.getEndpointReferences().clear(); - reference.getEndpointReferences().add(er); - return; - } - } - } + private void setSingleAutoWireTarget(ComponentReference reference) { + if (reference.getEndpointReferences().size() > 1 && reference.getBindings() != null + && reference.getBindings().size() == 1) { + String uri = reference.getBindings().get(0).getURI(); + if (uri != null) { + if (uri.indexOf('/') > -1) { + // TODO: must be a way to avoid this fiddling + int i = uri.indexOf('/'); + String c = uri.substring(0, i); + String s = uri.substring(i + 1); + uri = c + "#service(" + s + ")"; + } + for (EndpointReference er : reference.getEndpointReferences()) { + if (er.getTargetEndpoint() != null && uri.equals(er.getTargetEndpoint().getURI())) { + reference.getEndpointReferences().clear(); + reference.getEndpointReferences().add(er); + return; + } + } + } } - } - + } + } // end class 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 2bac74bbed..41d90a9d31 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 @@ -49,7 +49,8 @@ public class ComponentReferencePromotionBuilderImpl implements CompositeBuilder this.assemblyFactory = factories.getFactory(AssemblyFactory.class); } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { configureNestedCompositeReferences(composite, monitor); return composite; } 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 281f5dab95..b775e23143 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 @@ -46,7 +46,8 @@ public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuil this.assemblyFactory = assemblyFactory; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { wireCompositeReferences(composite, monitor); return composite; } 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 65559bcfdd..724240a35a 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 @@ -50,7 +50,8 @@ public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implement return "org.apache.tuscany.sca.assembly.builder.ComponentReferenceWireBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { wireComponentReferences(composite, monitor); return composite; } @@ -64,37 +65,36 @@ public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implement protected void wireComponentReferences(Composite composite, Monitor monitor) { monitor.pushContext(composite.getName().toString()); - + try { // Wire nested composites recursively for (Component component : composite.getComponents()) { Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { - - wireComponentReferences((Composite)implementation, monitor); - + + wireComponentReferences((Composite)implementation, monitor); + } } - + // Index components, services and references Map<String, Component> components = new HashMap<String, Component>(); Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); - + // Connect component references as described in wires connectWires(composite, componentServices, componentReferences, monitor); - - + // Finally clear the original reference target lists as we now have // bindings to represent the targets // for (ComponentReference componentReference : componentReferences.values()) { // componentReference.getTargets().clear(); // } - + } finally { monitor.popContext(); - } + } } @@ -156,9 +156,9 @@ public class ComponentReferenceWireBuilderImpl extends BaseBuilderImpl implement .isCompatible(resolvedReference.getInterfaceContract(), resolvedService.getInterfaceContract())) { //resolvedReference.getTargets().add(resolvedService); - if (wire.isReplace()) { - resolvedReference.getTargets().clear(); - } + if (wire.isReplace()) { + resolvedReference.getTargets().clear(); + } resolvedReference.getTargets().add(wire.getTarget()); } else { warning(monitor, "WireIncompatibleInterface", composite, source.getName(), target.getName()); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java index 83ae773e1b..9616eb024e 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java @@ -40,7 +40,7 @@ import org.apache.tuscany.sca.monitor.Monitor; */ public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { private BuilderExtensionPoint builders; - + public ComponentServiceBindingBuilderImpl(ExtensionPointRegistry registry) { this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); } @@ -49,7 +49,8 @@ public class ComponentServiceBindingBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.ComponentServiceBindingBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { buildServiceBindings(composite, monitor); return composite; } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java index dae85d4736..86c60b713d 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceEndpointBuilderImpl.java @@ -66,7 +66,8 @@ public class ComponentServiceEndpointBuilderImpl implements CompositeBuilder { * @param definitions * @param monitor - a Monitor for logging errors */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { // process component services if (!useNew) { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java index 94b3e6290a..89e7046c85 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java @@ -47,7 +47,8 @@ public class ComponentServicePromotionBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.ComponentServicePromotionBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { // Process nested composites recursively configureNestedCompositeServices(composite); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java index 291f418c1a..ccf96835db 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingConfigurationBuilderImpl.java @@ -49,7 +49,8 @@ public class CompositeBindingConfigurationBuilderImpl extends CompositeBindingUR return "org.apache.tuscany.sca.assembly.builder.CompositeServiceBindingBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { List<Binding> defaultBindings = null; for (Object x : composite.getExtensions()) { if (x instanceof List) { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java index 26d9a62b3f..3ae96e6f75 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java @@ -50,7 +50,8 @@ import org.apache.tuscany.sca.monitor.Monitor; * * @version $Rev$ $Date$ */ -public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements CompositeBuilder, DeployedCompositeBuilder { +public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements CompositeBuilder, + DeployedCompositeBuilder { public CompositeBindingURIBuilderImpl(ExtensionPointRegistry registry) { super(registry); @@ -60,15 +61,16 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C return "org.apache.tuscany.sca.assembly.builder.CompositeBindingURIBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { configureBindingURIsAndNames(composite, definitions, monitor); return composite; } public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { + Definitions definitions, + Map<QName, List<String>> bindingBaseURIs, + Monitor monitor) throws CompositeBuilderException { configureBindingURIs(composite, null, definitions, bindingBaseURIs, monitor); configureBindingNames(composite, monitor); return composite; @@ -125,14 +127,14 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C Definitions definitions, Map<QName, List<String>> defaultBindings, Monitor monitor) throws CompositeBuilderException { - + String parentComponentURI = uri; - + monitor.pushContext("Composite: " + composite.getName().toString()); - try { + try { // Process nested composites recursively for (Component component : composite.getComponents()) { - + // Initialize component URI String componentURI; if (parentComponentURI == null) { @@ -141,42 +143,46 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C componentURI = URI.create(parentComponentURI + '/').resolve(component.getName()).toString(); } component.setURI(componentURI); - + Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { // Process nested composite - configureBindingURIs((Composite)implementation, componentURI, definitions, defaultBindings, monitor); + configureBindingURIs((Composite)implementation, componentURI, definitions, defaultBindings, monitor); } } - + // Initialize composite service binding URIs List<Service> compositeServices = composite.getServices(); for (Service service : compositeServices) { // Set default binding names - + // Create default SCA binding attachSCABinding(service, definitions); - + constructBindingNames(service, monitor); - + // Initialize binding names and URIs for (Binding binding : service.getBindings()) { constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings, monitor); } } - + // Initialize component service binding URIs for (Component component : composite.getComponents()) { - + monitor.pushContext("Component: " + component.getName()); - + try { // Index properties, services and references Map<String, Service> services = new HashMap<String, Service>(); Map<String, Reference> references = new HashMap<String, Reference>(); Map<String, Property> properties = new HashMap<String, Property>(); - indexImplementationPropertiesServicesAndReferences(component, services, references, properties, monitor); - + indexImplementationPropertiesServicesAndReferences(component, + services, + references, + properties, + monitor); + // Index component services, references and properties // Also check for duplicates Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); @@ -187,7 +193,7 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C componentReferences, componentProperties, monitor); - + // Reconcile component services/references/properties and // implementation services/references and create component // services/references/properties for the services/references @@ -195,14 +201,14 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C reconcileServices(component, services, componentServices, monitor); reconcileReferences(component, references, componentReferences, monitor); reconcileProperties(component, properties, componentProperties, monitor); - + for (ComponentService service : component.getServices()) { - + // Create default SCA binding attachSCABinding(service, definitions); - + constructBindingNames(service, monitor); - + // Initialize binding names and URIs for (Binding binding : service.getBindings()) { constructBindingURI(component, service, binding, defaultBindings, monitor); @@ -214,7 +220,7 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C } } finally { monitor.popContext(); - } + } } /** @@ -283,7 +289,7 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C : "MultipleBindingsForReference", binding, contract.getName(), binding.getName()); } } - + if (contract.getCallback() != null) { bindings = contract.getCallback().getBindings(); bindingMap.clear(); @@ -361,9 +367,9 @@ public class CompositeBindingURIBuilderImpl extends BaseBuilderImpl implements C Monitor monitor) throws CompositeBuilderException { try { - + boolean includeBindingName = !service.getName().equals(binding.getName()); - + // calculate the service binding URI URI bindingURI; if (binding.getURI() != null) { 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 143e4e7850..0e5bd2edb7 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 @@ -64,7 +64,6 @@ public class CompositeBuilderImpl implements CompositeBuilder, DeployedComposite private CompositeBuilder componentServiceEndpointBuilder; private BuilderExtensionPoint builders; - /** * Constructs a new composite builder. @@ -72,23 +71,21 @@ public class CompositeBuilderImpl implements CompositeBuilder, DeployedComposite * @param registry */ public CompositeBuilderImpl(ExtensionPointRegistry registry) { - + FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); this.builders = registry.getExtensionPoint(BuilderExtensionPoint.class); AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); - + compositeIncludeBuilder = new CompositeIncludeBuilderImpl(); componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(registry); //componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, endpointFactory); componentReferencePromotionBuilder = new ComponentReferencePromotionBuilderImpl(registry); //compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory); compositeCloneBuilder = new CompositeCloneBuilderImpl(); - componentConfigurationBuilder = - new ComponentConfigurationBuilderImpl(registry); + componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(registry); compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(registry); compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(registry); - compositeBindingURIBuilder = - new CompositeBindingURIBuilderImpl(registry); + compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(registry); //componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory); //compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory); compositePromotionBuilder = new CompositePromotionBuilderImpl(registry); @@ -96,8 +93,7 @@ public class CompositeBuilderImpl implements CompositeBuilder, DeployedComposite componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(registry); componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(registry); - componentReferenceEndpointReferenceBuilder = - new ComponentReferenceEndpointReferenceBuilderImpl(registry); + componentReferenceEndpointReferenceBuilder = new ComponentReferenceEndpointReferenceBuilderImpl(registry); componentServiceEndpointBuilder = new ComponentServiceEndpointBuilderImpl(assemblyFactory); //endpointReferenceBuilder = new EndpointReference2BuilderImpl(assemblyFactory, interfaceContractMapper); } @@ -106,18 +102,19 @@ public class CompositeBuilderImpl implements CompositeBuilder, DeployedComposite return "org.apache.tuscany.sca.assembly.builder.CompositeBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { build(composite, definitions, null, monitor); return composite; } public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { + Definitions definitions, + Map<QName, List<String>> bindingBaseURIs, + Monitor monitor) throws CompositeBuilderException { try { - + // Collect and fuse includes composite = compositeIncludeBuilder.build(composite, definitions, monitor); @@ -140,7 +137,11 @@ public class CompositeBuilderImpl implements CompositeBuilder, DeployedComposite // Configure service binding URIs and names. Creates an SCA defined URI based // on the scheme base URI, the component name and the binding name - composite = ((DeployedCompositeBuilder)compositeBindingURIBuilder).build(composite, definitions, bindingBaseURIs, monitor); + composite = + ((DeployedCompositeBuilder)compositeBindingURIBuilder).build(composite, + definitions, + bindingBaseURIs, + monitor); // Create $promoted$ component services on bottom level components // to represent promoted services @@ -185,11 +186,11 @@ public class CompositeBuilderImpl implements CompositeBuilder, DeployedComposite // Compute the policies across the model hierarchy composite = compositePolicyBuilder.build(composite, definitions, monitor); - + return composite; } catch (Exception e) { throw new CompositeBuilderException("Exception while building composite " + composite.getName(), e); - } // end try + } // end try } // end method build diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java index b5476805ad..07c1c0c7fc 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java @@ -41,7 +41,8 @@ public class CompositeCloneBuilderImpl implements CompositeBuilder { public CompositeCloneBuilderImpl() { } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { expandCompositeImplementations(composite); return composite; } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeComponentTypeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeComponentTypeBuilderImpl.java index cf47255f36..d696496a19 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeComponentTypeBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeComponentTypeBuilderImpl.java @@ -60,11 +60,11 @@ import org.apache.tuscany.sca.policy.PolicySubject; public class CompositeComponentTypeBuilderImpl { private static final Logger logger = Logger.getLogger(CompositeComponentTypeBuilderImpl.class.getName()); - + protected static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200903"; protected static final String BINDING_SCA = "binding.sca"; - protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); - + protected static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); + private ComponentBuilderImpl componentBuilder; private Monitor monitor; private AssemblyFactory assemblyFactory; @@ -72,21 +72,20 @@ public class CompositeComponentTypeBuilderImpl { private InterfaceContractMapper interfaceContractMapper; private BuilderExtensionPoint builders; - - public CompositeComponentTypeBuilderImpl(ExtensionPointRegistry registry){ + public CompositeComponentTypeBuilderImpl(ExtensionPointRegistry registry) { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); monitor = monitorFactory.createMonitor(); - + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); builders = registry.getExtensionPoint(BuilderExtensionPoint.class); } - - public void setComponentBuilder(ComponentBuilderImpl componentBuilder){ + + public void setComponentBuilder(ComponentBuilderImpl componentBuilder) { this.componentBuilder = componentBuilder; } @@ -96,34 +95,30 @@ public class CompositeComponentTypeBuilderImpl { * @param implementation * @return component type */ - public void createComponentType(Implementation implementation){ - if (!(implementation instanceof Composite)){ + public void createComponentType(Implementation implementation) { + if (!(implementation instanceof Composite)) { // component type will have been calculated at resolve time return; } - + // create the composite component type as this was not // calculated at resolve time Composite composite = (Composite)implementation; - + // first make sure that each child component has been properly configured based // on its own component type for (Component component : composite.getComponents()) { - + // Check for duplicate component names if (composite.getComponent(component.getName()) == null) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "DuplicateComponentName", - composite.getName().toString(), - component.getName()); - } - + Monitor.error(monitor, this, "assembly-validation-messages", "DuplicateComponentName", composite + .getName().toString(), component.getName()); + } + // do any work we need to do before we configure the component // Anything that needs to be pushed down the promotion // hierarchy must be done before we configure the component - + // Push down the autowire flag from the composite to components if (component.getAutowire() == null) { component.setAutowire(composite.getAutowire()); @@ -135,29 +130,28 @@ public class CompositeComponentTypeBuilderImpl { // create the composite component type based on the promoted artifacts // from the components that it contains - + // index all the components, services and references in the // component type so that they are easy to find Map<String, Component> components = new HashMap<String, Component>(); Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>(); indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences); - + // services calculateServices(composite, components, componentServices); - + // references calculateReferences(composite, components, componentReferences); - + // properties // Properties on the composite component are unaffected by properties // on child components. Instead child component properties might take their // values from component properties. Hence there is nothing to do here. //calculateProperties(composite, components); - - + } - + /** * Index components, services and references inside a composite. * @@ -208,9 +202,8 @@ public class CompositeComponentTypeBuilderImpl { componentReferences.put(uri, componentReference); } } - } - - + } + /** * Connect the services in the component type to the component services that * they promote @@ -220,34 +213,32 @@ public class CompositeComponentTypeBuilderImpl { */ private void calculateServices(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentService> componentServices){ + Map<String, ComponentService> componentServices) { // Connect this component type's services to the // services from child components which it promotes - connectPromotedServices(componentType, - components, - componentServices); - + connectPromotedServices(componentType, components, componentServices); + // look at each component type service in turn and // calculate its configuration based on OASIS rules for (Service service : componentType.getServices()) { CompositeService compositeService = (CompositeService)service; ComponentService promotedComponentService = compositeService.getPromotedService(); - + // promote interface contracts calculatePromotedInterfaceContract(compositeService, promotedComponentService); - + // promote bindings calculatePromotedBindings(compositeService, promotedComponentService); - + // promote intents - done later in CompositePolicyBuilder - discuss with RF // calculatePromotedIntents(compositeService, promotedComponentService); - + // promote policy sets - done later in CompositePolicyBuilder - discuss with RF // calculatePromotedPolicySets(compositeService, promotedComponentService); - } + } } - + /** * Connect the references in the component type to the component references that * they promote @@ -257,39 +248,37 @@ public class CompositeComponentTypeBuilderImpl { */ private void calculateReferences(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentReference> componentReferences){ + Map<String, ComponentReference> componentReferences) { // Connect this component type's references to the // references from child components which it promotes - connectPromotedReferences(componentType, - components, - componentReferences); - + connectPromotedReferences(componentType, components, componentReferences); + // look at each component type reference in turn and // calculate its configuration based on OASIS rules for (Reference reference : componentType.getReferences()) { CompositeReference compositeReference = (CompositeReference)reference; List<ComponentReference> promotedReferences = compositeReference.getPromotedReferences(); - - for(ComponentReference promotedComponentReference : promotedReferences){ - + + for (ComponentReference promotedComponentReference : promotedReferences) { + // promote interface contracts calculatePromotedInterfaceContract(compositeReference, promotedComponentReference); - + // promote bindings // Don't need to promote reference bindings as any lower level binding will // already be targeting the correct service without need for promotion //calculatePromotedBindings(compositeReference, promotedComponentReference); - + // promote intents - done later in CompositePolicyBuilder - discuss with RF // calculatePromotedIntents(compositeService, promotedComponentService); - + // promote policy sets - done later in CompositePolicyBuilder - discuss with RF // calculatePromotedPolicySets(compositeService, promotedComponentService); } - } - } - + } + } + /** * Connect the services in the component type to the component services that * they promote @@ -299,7 +288,7 @@ public class CompositeComponentTypeBuilderImpl { */ private void connectPromotedServices(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentService> componentServices){ + Map<String, ComponentService> componentServices) { for (Service service : componentType.getServices()) { // Connect composite (component type) services to the component services @@ -320,10 +309,10 @@ public class CompositeComponentTypeBuilderImpl { } else { promotedServiceName = promotedComponentName; } - + // find the promoted service ComponentService promotedService = componentServices.get(promotedServiceName); - + if (promotedService != null) { // Point to the resolved component @@ -333,17 +322,17 @@ public class CompositeComponentTypeBuilderImpl { // Point to the resolved component service compositeService.setPromotedService(promotedService); } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "PromotedServiceNotFound", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "PromotedServiceNotFound", ((Composite)componentType).getName().toString(), promotedServiceName); - } + } } - } - } - + } + } + /** * Connect the references in the component type to the component references that * they promote @@ -353,8 +342,8 @@ public class CompositeComponentTypeBuilderImpl { */ private void connectPromotedReferences(ComponentType componentType, Map<String, Component> components, - Map<String, ComponentReference> componentReferences){ - + Map<String, ComponentReference> componentReferences) { + // Connect composite (component type) references to the component references that they promote for (Reference reference : componentType.getReferences()) { CompositeReference compositeReference = (CompositeReference)reference; @@ -373,7 +362,7 @@ public class CompositeComponentTypeBuilderImpl { componentReference.setPromoted(true); // Point to the resolved component reference - promotedReferences.set(i, componentReference); + promotedReferences.set(i, componentReference); } else { Monitor.error(monitor, this, @@ -384,9 +373,9 @@ public class CompositeComponentTypeBuilderImpl { } } } - } + } } - + /** * Create a default SCA binding in the case that no binding * is specified by the user @@ -408,41 +397,39 @@ public class CompositeComponentTypeBuilderImpl { contract.getBindings().add(scaBinding); contract.setOverridingBindings(false); - } - + } + /** * The following methods implement rules that the OASIS specification defined explicitly * to control how configuration from a component type is inherited by a component - */ - + */ + /** * OASIS RULE: Interface contract from higher in the implementation hierarchy takes precedence * * @param topContract the top contract * @param bottomContract the bottom contract - */ - private void calculatePromotedInterfaceContract(Contract topContract, - Contract bottomContract) { + */ + private void calculatePromotedInterfaceContract(Contract topContract, Contract bottomContract) { // Use the interface contract from the bottom level contract if // none is specified on the top level contract InterfaceContract topInterfaceContract = topContract.getInterfaceContract(); InterfaceContract bottomInterfaceContract = bottomContract.getInterfaceContract(); - + if (topInterfaceContract == null) { topContract.setInterfaceContract(bottomInterfaceContract); } else if (bottomInterfaceContract != null) { // Check that the top and bottom interface contracts are compatible - boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract, - bottomInterfaceContract); + boolean isCompatible = interfaceContractMapper.isCompatible(topInterfaceContract, bottomInterfaceContract); if (!isCompatible) { if (topContract instanceof Reference) { - Monitor.error(monitor, + Monitor.error(monitor, this, "assembly-validation-messages", "ReferenceInterfaceNotSubSet", topContract.getName()); } else { - Monitor.error(monitor, + Monitor.error(monitor, this, "assembly-validation-messages", "ServiceInterfaceNotSubSet", @@ -450,16 +437,15 @@ public class CompositeComponentTypeBuilderImpl { } } } - } - + } + /** * OASIS RULE: Bindings from higher in the implementation hierarchy take precedence * * @param compositeService * @param promotedComponentService - */ - private void calculatePromotedBindings(CompositeService compositeService, - ComponentService promotedComponentService){ + */ + private void calculatePromotedBindings(CompositeService compositeService, ComponentService promotedComponentService) { // forward bindings if (compositeService.getBindings().isEmpty()) { for (Binding binding : promotedComponentService.getBindings()) { @@ -470,28 +456,27 @@ public class CompositeComponentTypeBuilderImpl { } } } - + if (compositeService.getBindings().isEmpty()) { createSCABinding(compositeService, null); } // callback bindings - if (promotedComponentService.getCallback() != null){ + if (promotedComponentService.getCallback() != null) { if (compositeService.getCallback() != null) { compositeService.getCallback().getBindings().clear(); } else { compositeService.setCallback(assemblyFactory.createCallback()); } - + for (Binding binding : promotedComponentService.getCallback().getBindings()) { try { compositeService.getCallback().getBindings().add((Binding)binding.clone()); } catch (CloneNotSupportedException ex) { // this binding can't be used in the promoted service } - } - } - } - + } + } + } } //end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java index 2f9fee7a3a..52dd769f8a 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java @@ -46,7 +46,8 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.CompositeIncludeBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { fuseIncludes(composite, monitor); return composite; } @@ -57,22 +58,18 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { * @param composite */ private void fuseIncludes(Composite composite, Monitor monitor) { - + monitor.pushContext("Composite: " + composite.getName().toString()); - + try { Set<Composite> visited = new HashSet<Composite>(); visited.add(composite); - + for (Composite included : composite.getIncludes()) { - if(included.isLocal() && !composite.isLocal()) { + if (included.isLocal() && !composite.isLocal()) { // ASM60041 - Monitor.error(monitor, - this, - "assembly-validation-messages", - "IllegalCompositeIncusion", - composite.getName().toString(), - included.getName().toString()); + Monitor.error(monitor, this, "assembly-validation-messages", "IllegalCompositeIncusion", composite + .getName().toString(), included.getName().toString()); } Composite fusedComposite = fuseInclude(included, visited, monitor); if (fusedComposite != null) { @@ -83,16 +80,16 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { composite.getWires().addAll(fusedComposite.getWires()); } } - + // Clear the list of includes as all of the included components // have now been added into the top level composite composite.getIncludes().clear(); - + // process any composites referenced through implementation.composite for (Component component : composite.getComponents()) { monitor.pushContext("Component: " + component.getName()); - - try { + + try { // recurse for composite implementations Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { @@ -101,11 +98,11 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { } finally { monitor.popContext(); } - } - + } + } finally { monitor.popContext(); - } + } } private Composite fuseInclude(Composite include, Set<Composite> visited, Monitor monitor) { @@ -113,11 +110,8 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { if (visited.contains(include)) { // FIXME: [rfeng] Do we need to have a warning? I think it is fine to have Composite A // include B and C while both B and C include D. - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "CompositeAlreadyIncluded", - include.getName().toString()); + Monitor.warning(monitor, this, "assembly-validation-messages", "CompositeAlreadyIncluded", include + .getName().toString()); return null; } @@ -132,17 +126,13 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { // get the components etc. from any included composites for (Composite included : include.getIncludes()) { - if(included.isLocal() && !include.isLocal()) { + if (included.isLocal() && !include.isLocal()) { // ASM60041 - Monitor.error(monitor, - this, - "assembly-validation-messages", - "IllegalCompositeIncusion", - include.getName().toString(), - included.getName().toString()); - return null; + Monitor.error(monitor, this, "assembly-validation-messages", "IllegalCompositeIncusion", include + .getName().toString(), included.getName().toString()); + return null; } - + Composite fusedComposite = fuseInclude(included, visited, monitor); if (fusedComposite != null) { clone.getComponents().addAll(fusedComposite.getComponents()); @@ -167,24 +157,24 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { } } } - + // Merge the intents and policySets from the included composite into // component/service/reference elements under the composite - for(Component component : clone.getComponents()) { + for (Component component : clone.getComponents()) { component.getRequiredIntents().addAll(include.getRequiredIntents()); component.getPolicySets().addAll(include.getPolicySets()); } - - for(Service service: clone.getServices()) { + + for (Service service : clone.getServices()) { service.getRequiredIntents().addAll(include.getRequiredIntents()); service.getPolicySets().addAll(include.getPolicySets()); } - for(Reference reference: clone.getReferences()) { + for (Reference reference : clone.getReferences()) { reference.getRequiredIntents().addAll(include.getRequiredIntents()); reference.getPolicySets().addAll(include.getPolicySets()); } - + // process any composites referenced through implementation.composite for (Component component : clone.getComponents()) { @@ -199,7 +189,7 @@ public class CompositeIncludeBuilderImpl implements CompositeBuilder { } } } - + clone.getIncludes().clear(); // return the fused composite we have built up so far 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 fbffb2c4ab..4f16988fe8 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 @@ -56,12 +56,13 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo public CompositePolicyBuilderImpl(ExtensionPointRegistry registry) { super(registry); } - + public String getID() { return "org.apache.tuscany.sca.assembly.builder.CompositePolicyBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { computePolicies(composite, definitions, monitor); return composite; } @@ -181,14 +182,14 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo return name2.equals(name1); } } - + private Intent resolve(Definitions definitions, Intent proxy) { - for(Intent i: definitions.getIntents()) { - if(i.equals(proxy)) { + for (Intent i : definitions.getIntents()) { + if (i.equals(proxy)) { return i; } - for(Intent qi: i.getQualifiedIntents()) { - if(qi.equals(proxy)) { + for (Intent qi : i.getQualifiedIntents()) { + if (qi.equals(proxy)) { return qi; } } @@ -279,7 +280,7 @@ public class CompositePolicyBuilderImpl extends BaseBuilderImpl implements Compo } } } - + subject.getPolicySets().clear(); subject.getPolicySets().addAll(policySets); 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 fffc63626f..274d6db83e 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 @@ -55,7 +55,8 @@ public class CompositePromotionBuilderImpl extends BaseBuilderImpl implements Co return "org.apache.tuscany.sca.assembly.builder.CompositePromotionBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { connectCompositeReferencesAndServices(composite, monitor); return composite; } @@ -68,9 +69,9 @@ public class CompositePromotionBuilderImpl extends BaseBuilderImpl implements Co * @param problems */ protected void connectCompositeReferencesAndServices(Composite composite, Monitor monitor) { - + monitor.pushContext("Composite: " + composite.getName().toString()); - + try { // Wire nested composites recursively for (Component component : composite.getComponents()) { @@ -79,13 +80,13 @@ public class CompositePromotionBuilderImpl extends BaseBuilderImpl implements Co connectCompositeReferencesAndServices((Composite)implementation, monitor); } } - + // Index components, services and references Map<String, Component> components = new HashMap<String, Component>(); Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>(); 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, monitor); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java index c50caa245b..51cea9100e 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java @@ -55,7 +55,8 @@ public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuil return "org.apache.tuscany.sca.assembly.builder.CompositeReferenceConfigurationBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { // Process nested composites recursively configureNestedCompositeReferences(composite); @@ -87,7 +88,7 @@ public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuil if (compositeReference.getInterfaceContract() != null && compositeReference.getInterfaceContract() .getCallbackInterface() != null) { if (isCallbackOverridingBindings(compositeReference)) { - compositeReference.setPromotionOverride(true); + compositeReference.setPromotionOverride(true); } else if (isCallbackOverridingBindings(promotedReference)) { if (compositeReference.getCallback() != null) { compositeReference.getCallback().getBindings().clear(); @@ -108,8 +109,8 @@ public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuil // Because the component reference bindings can all be different, we don't // copy any of them up to this composite reference, which will therefore always // have its own binding, even if it's only the default SCA binding. - if (compositeReference.isOverridingBindings() || (compositeReference - .getCallback() != null && !compositeReference.getCallback().getBindings().isEmpty())) { + if (compositeReference.isOverridingBindings() || (compositeReference.getCallback() != null && !compositeReference + .getCallback().getBindings().isEmpty())) { compositeReference.setPromotionOverride(true); } } @@ -160,8 +161,7 @@ public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuil } if (componentReference.getInterfaceContract() != null && componentReference .getInterfaceContract().getCallbackInterface() != null) { - if (!isCallbackOverridingBindings(compositeReference) - && isCallbackOverridingBindings(promotedReference)) { + if (!isCallbackOverridingBindings(compositeReference) && isCallbackOverridingBindings(promotedReference)) { if (compositeReference.getCallback() != null) { compositeReference.getCallback().getBindings().clear(); } else { @@ -170,8 +170,8 @@ public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuil compositeReference.getCallback().getBindings().addAll(promotedReference .getCallback().getBindings()); } - if (componentReference.getCallback() != null && !componentReference - .getCallback().getBindings().isEmpty()) { + if (componentReference.getCallback() != null && !componentReference.getCallback() + .getBindings().isEmpty()) { componentReference.setPromotionOverride(true); } else if (isCallbackOverridingBindings(compositeReference)) { if (componentReference.getCallback() != null) { @@ -194,8 +194,7 @@ public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuil // Because the lower-level component reference bindings can all be different, // we don't copy any of them up to this component reference, which will therefore // always have its own binding, even if it's only the default SCA binding. - if (componentReference.isOverridingBindings() - || isCallbackOverridingBindings(componentReference)) { + if (componentReference.isOverridingBindings() || isCallbackOverridingBindings(componentReference)) { componentReference.setPromotionOverride(true); } } @@ -205,7 +204,7 @@ public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuil } } } - + private boolean isCallbackOverridingBindings(Contract contract) { Callback callback = contract.getCallback(); return callback != null && !callback.getBindings().isEmpty(); 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 19bc339b05..9daf1b67b2 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 @@ -53,7 +53,8 @@ public class CompositeReferenceWireBuilderImpl implements CompositeBuilder { * * @param composite */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { // Process composite references declared in this composite for (Reference reference : composite.getReferences()) { diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java index f023bc869c..d06b686b48 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java @@ -50,7 +50,8 @@ public class CompositeServiceBindingBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.CompositeServiceBindingBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { buildServiceBindings(composite, monitor); return composite; } diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java index 8e6b5419dc..e690e26170 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java @@ -53,7 +53,8 @@ public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilde return "org.apache.tuscany.sca.assembly.builder.CompositeServiceConfigurationBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { // Process nested composites recursively configureNestedCompositeServices(composite); @@ -80,8 +81,7 @@ public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilde } if (compositeService.getInterfaceContract() != null && compositeService.getInterfaceContract() .getCallbackInterface() != null) { - if (!isCallbackOverridingBindings(compositeService) - && isCallbackOverridingBindings(promotedService)) { + if (!isCallbackOverridingBindings(compositeService) && isCallbackOverridingBindings(promotedService)) { if (compositeService.getCallback() != null) { compositeService.getCallback().getBindings().clear(); } else { @@ -138,8 +138,7 @@ public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilde } if (componentService.getInterfaceContract() != null && componentService .getInterfaceContract().getCallbackInterface() != null) { - if (!isCallbackOverridingBindings(compositeService) - && isCallbackOverridingBindings(promotedService)) { + if (!isCallbackOverridingBindings(compositeService) && isCallbackOverridingBindings(promotedService)) { if (compositeService.getCallback() != null) { compositeService.getCallback().getBindings().clear(); } else { @@ -169,7 +168,7 @@ public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilde } } } - + private boolean isCallbackOverridingBindings(Contract contract) { Callback callback = contract.getCallback(); return callback != null && !callback.getBindings().isEmpty(); diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java index 84a1a38fb5..2b2634bcd3 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java @@ -46,7 +46,8 @@ public class CompositeServicePromotionBuilderImpl implements CompositeBuilder { return "org.apache.tuscany.sca.assembly.builder.CompositeServicePromotionBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { // Process top level composite services for (Service service : composite.getServices()) { 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 index b05d2bba3e..54f6d0e850 100644 --- 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 @@ -50,7 +50,8 @@ public class EndpointBuilderImpl { * @param definitions * @param monitor - a Monitor for logging errors */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { processComponentServices(composite); return composite; @@ -96,5 +97,5 @@ public class EndpointBuilderImpl { } // end for } } - } -} + } +} diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReferenceBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReferenceBuilderImpl.java index e59a381c72..0e810e8ce5 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReferenceBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointReferenceBuilderImpl.java @@ -55,24 +55,23 @@ public class EndpointReferenceBuilderImpl { private AssemblyFactory assemblyFactory; private InterfaceContractMapper interfaceContractMapper; - public EndpointReferenceBuilderImpl(ExtensionPointRegistry registry) { UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); monitor = monitorFactory.createMonitor(); interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class); - + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); } - /** * Create endpoint references for all component references. * * @param composite */ - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { this.monitor = monitor; // process component services @@ -92,56 +91,61 @@ public class EndpointReferenceBuilderImpl { // Connect component references as described in wires connectWires(composite, componentServices, componentReferences, monitor); - + // create endpoint references for each component's references for (Component component : composite.getComponents()) { monitor.pushContext("Component: " + component.getName()); - + try { - + // recurse for composite implementations Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { processComponentReferences((Composite)implementation); } - + // create endpoint references to represent the component reference for (ComponentReference reference : component.getReferences()) { - createReferenceEndpointReferences(composite, component, reference, components, componentServices); - + createReferenceEndpointReferences(composite, + component, + reference, + components, + componentServices); + // fix up links between endpoints and endpoint references that represent callbacks for (ComponentService service : component.getServices()) { if ((service.getInterfaceContract() != null) && (service.getInterfaceContract() .getCallbackInterface() != null)) { if (reference.getName().equals(service.getName())) { for (Endpoint endpoint : service.getEndpoints()) { - endpoint.getCallbackEndpointReferences().addAll(reference.getEndpointReferences()); + endpoint.getCallbackEndpointReferences().addAll(reference + .getEndpointReferences()); } break; } // end if } // end if } // end for } // end for - + // Validate that references are wired or promoted, according // to their multiplicity validateReferenceMultiplicity(composite, component); - + } finally { monitor.popContext(); } } // end for - + } finally { monitor.popContext(); } } // end method processCompoenntReferences - + protected void indexComponentsServicesAndReferences(Composite composite, - Map<String, Component> components, - Map<String, ComponentService> componentServices, - Map<String, ComponentReference> componentReferences) { + Map<String, Component> components, + Map<String, ComponentService> componentServices, + Map<String, ComponentReference> componentReferences) { for (Component component : composite.getComponents()) { @@ -153,15 +157,13 @@ public class EndpointReferenceBuilderImpl { for (ComponentService componentService : component.getServices()) { // Index component services by component name / service name - String uri = component.getName() + '/' - + componentService.getName(); + String uri = component.getName() + '/' + componentService.getName(); componentServices.put(uri, componentService); // TODO - EPR - $promoted$ no longer used but it doesn't do any // harm here boolean promotedService = false; - if (componentService.getName() != null - && componentService.getName().indexOf("$promoted$") > -1) { + if (componentService.getName() != null && componentService.getName().indexOf("$promoted$") > -1) { promotedService = true; } @@ -186,15 +188,13 @@ public class EndpointReferenceBuilderImpl { } // Index references by component name / reference name - for (ComponentReference componentReference : component - .getReferences()) { - String uri = component.getName() + '/' - + componentReference.getName(); + for (ComponentReference componentReference : component.getReferences()) { + String uri = component.getName() + '/' + componentReference.getName(); componentReferences.put(uri, componentReference); } } - } - + } + /** * Resolve wires and connect the sources to their targets * @@ -224,12 +224,9 @@ public class EndpointReferenceBuilderImpl { if (resolvedReference != null) { wire.setSource(resolvedReference); } else { - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "WireSourceNotFound", - source.getName()); - } + Monitor.warning(monitor, this, "assembly-validation-messages", "WireSourceNotFound", source + .getName()); + } } else { resolvedReference = wire.getSource(); } @@ -241,11 +238,8 @@ public class EndpointReferenceBuilderImpl { if (resolvedService != null) { wire.setTarget(target); } else { - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "WireTargetNotFound", - target.getName()); + Monitor.warning(monitor, this, "assembly-validation-messages", "WireTargetNotFound", target + .getName()); } } else { resolvedService = wire.getTarget(); @@ -266,28 +260,24 @@ public class EndpointReferenceBuilderImpl { } resolvedReference.getTargets().add(wire.getTarget()); } else { - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "WireIncompatibleInterface", - source.getName(), - target.getName()); + Monitor.warning(monitor, this, "assembly-validation-messages", "WireIncompatibleInterface", source + .getName(), target.getName()); } } } // Clear the list of wires composite.getWires().clear(); - } + } private void createReferenceEndpointReferences(Composite composite, Component component, ComponentReference reference, Map<String, Component> components, Map<String, ComponentService> componentServices) { - + monitor.pushContext("Reference: " + reference.getName()); - + // Get reference targets List<ComponentService> refTargets = getReferenceTargets(reference); if (reference.getAutowire() == Boolean.TRUE && reference.getTargets().isEmpty()) { @@ -296,11 +286,11 @@ public class EndpointReferenceBuilderImpl { // autowired reference Multiplicity multiplicity = reference.getMultiplicity(); for (Component targetComponent : composite.getComponents()) { - + // Tuscany specific selection of the first autowire reference // when there are more than one (ASM_60025) - if ((multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) && - (reference.getEndpointReferences().size() != 0) ) { + if ((multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) && (reference + .getEndpointReferences().size() != 0)) { break; } @@ -327,10 +317,10 @@ public class EndpointReferenceBuilderImpl { if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { if (reference.getEndpointReferences().size() == 0) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "NoComponentReferenceTarget", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "NoComponentReferenceTarget", reference.getName()); } } @@ -341,10 +331,10 @@ public class EndpointReferenceBuilderImpl { // Check that the component reference does not mix the use of endpoint references // specified via the target attribute with the presence of binding elements if (bindingsIdentifyTargets(reference)) { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceEndPointMixWithTarget", + Monitor.error(monitor, + this, + "assembly-validation-messages", + "ReferenceEndPointMixWithTarget", composite.getName().toString(), component.getName(), reference.getName()); @@ -356,7 +346,7 @@ public class EndpointReferenceBuilderImpl { String targetName = getComponentServiceName(target.getName()); String bindingName = getBindingName(target.getName()); ComponentService targetComponentService = componentServices.get(targetName); - + Component targetComponent = getComponentFromTargetName(components, targetName); if (targetComponentService != null) { @@ -364,54 +354,58 @@ public class EndpointReferenceBuilderImpl { if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - if (bindingName != null){ + if (bindingName != null) { // the user has selected a binding as part of the target name Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()){ - if (tmp.getName().equals(bindingName)){ + + for (Binding tmp : targetComponentService.getBindings()) { + if (tmp.getName().equals(bindingName)) { targetBinding = tmp; continue; } } - - if (targetBinding != null){ + + if (targetBinding != null) { EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, targetBinding, true)); + endpointRef.setTargetEndpoint(createEndpoint(targetComponent, + targetComponentService, + targetBinding, + true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); // relying on the registry here to resolve the real endpoint reference.getEndpointReferences().add(endpointRef); - + } else { EndpointReference endpointRef = createEndpointRef(component, reference, true); endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); endpointRef.setRemote(true); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); reference.getEndpointReferences().add(endpointRef); - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ComponentReferenceTargetNotFound", + Monitor.warning(monitor, + this, + "assembly-validation-messages", + "ComponentReferenceTargetNotFound", composite.getName().toString(), - targetName); + targetName); } - + } else { // the user hasn't selected a binding as part of the target name EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); + endpointRef + .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); reference.getEndpointReferences().add(endpointRef); } } else { - Monitor.error(monitor, - this, - "assembly-validation-messages", - "ReferenceIncompatibleInterface", - composite.getName().toString(), - component.getName() + "." + reference.getName(), - targetName); + Monitor.error(monitor, + this, + "assembly-validation-messages", + "ReferenceIncompatibleInterface", + composite.getName().toString(), + component.getName() + "." + reference.getName(), + targetName); } } else { // add an unresolved endpoint reference with an unresolved endpoint to go with it @@ -420,12 +414,12 @@ public class EndpointReferenceBuilderImpl { endpointRef.setRemote(true); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); reference.getEndpointReferences().add(endpointRef); - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ComponentReferenceTargetNotFound", + Monitor.warning(monitor, + this, + "assembly-validation-messages", + "ComponentReferenceTargetNotFound", composite.getName().toString(), - targetName); + targetName); } // end if } // end for } // end if @@ -469,7 +463,7 @@ public class EndpointReferenceBuilderImpl { if (uri.startsWith("/")) { uri = uri.substring(1); } - + String targetName = getComponentServiceName(uri); String bindingName = getBindingName(uri); @@ -486,51 +480,56 @@ public class EndpointReferenceBuilderImpl { // a superset of the component reference interface if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatible(reference .getInterfaceContract(), targetComponentService.getInterfaceContract())) { - if (bindingName != null){ + if (bindingName != null) { // the user has selected a binding as part of the target name Binding targetBinding = null; - - for (Binding tmp : targetComponentService.getBindings()){ - if (tmp.getName().equals(bindingName)){ + + for (Binding tmp : targetComponentService.getBindings()) { + if (tmp.getName().equals(bindingName)) { targetBinding = tmp; continue; } } - - if (targetBinding != null){ + + if (targetBinding != null) { EndpointReference endpointRef = createEndpointRef(component, reference, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, targetBinding, true)); + endpointRef.setTargetEndpoint(createEndpoint(targetComponent, + targetComponentService, + targetBinding, + true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); // relying on the registry here to resolve the real endpoint reference.getEndpointReferences().add(endpointRef); - + } else { EndpointReference endpointRef = createEndpointRef(component, reference, true); endpointRef.setTargetEndpoint(createEndpoint(component, targetName)); endpointRef.setRemote(true); endpointRef.setStatus(EndpointReference.WIRED_TARGET_NOT_FOUND); reference.getEndpointReferences().add(endpointRef); - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ComponentReferenceTargetNotFound", + Monitor.warning(monitor, + this, + "assembly-validation-messages", + "ComponentReferenceTargetNotFound", composite.getName().toString(), - targetName); + targetName); } - + } else { // create endpoint reference with dummy endpoint which will be replaced when policies // are matched and bindings are configured later - EndpointReference endpointRef = createEndpointRef(component, reference, binding, null, false); - endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); + EndpointReference endpointRef = + createEndpointRef(component, reference, binding, null, false); + endpointRef + .setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); endpointRef.setStatus(EndpointReference.WIRED_TARGET_FOUND_READY_FOR_MATCHING); reference.getEndpointReferences().add(endpointRef); } } else { - Monitor.warning(monitor, - this, - "assembly-validation-messages", - "ReferenceIncompatibleInterface", + Monitor.warning(monitor, + this, + "assembly-validation-messages", + "ReferenceIncompatibleInterface", composite.getName().toString(), reference.getName(), uri); @@ -549,12 +548,12 @@ public class EndpointReferenceBuilderImpl { } // end if } } - + monitor.popContext(); - + } // end method - - private void validateReferenceMultiplicity(Composite composite, Component component){ + + private void validateReferenceMultiplicity(Composite composite, Component component) { for (ComponentReference componentReference : component.getReferences()) { if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), componentReference.getEndpointReferences())) { @@ -577,24 +576,24 @@ public class EndpointReferenceBuilderImpl { composite.getName().toString(), componentReference.getName()); } - } else { + } else { // no error if reference is autowire and more targets // than multiplicity have been found - if (componentReference.getAutowire() == Boolean.TRUE){ + if (componentReference.getAutowire() == Boolean.TRUE) { break; } - + Monitor.error(monitor, this, "assembly-validation-messages", - "TooManyReferenceTargets", - componentReference.getName()); + "TooManyReferenceTargets", + componentReference.getName()); } } } } - + /** * Evaluates whether the bindings attached to a reference identify one or more target services. * @param reference - the reference @@ -627,7 +626,7 @@ public class EndpointReferenceBuilderImpl { } // end if return theTargets; } // end method getReferenceTargets - + /** * Target names can take the form * component/service/binding @@ -638,14 +637,14 @@ public class EndpointReferenceBuilderImpl { */ private String getComponentServiceName(String targetName) { String[] parts = targetName.split("/"); - - if (parts.length > 1){ + + if (parts.length > 1) { return parts[0] + "/" + parts[1]; } else { return parts[0]; } - } - + } + /** * Target names can take the form * component/service/binding @@ -657,13 +656,13 @@ public class EndpointReferenceBuilderImpl { */ private String getBindingName(String targetName) { String[] parts = targetName.split("/"); - - if (parts.length == 3){ + + if (parts.length == 3) { return parts[2]; } else { return null; } - } + } /** * Helper method that finds the Component given a target name @@ -731,7 +730,7 @@ public class EndpointReferenceBuilderImpl { endpoint.setUnresolved(unresolved); return endpoint; } // end method createEndpoint - + /** * Helper method to create an endpoint * @param component @@ -815,26 +814,27 @@ public class EndpointReferenceBuilderImpl { * declares a single target service, the reference is wired only to * the single service identified by the <wire/> element */ - private void setSingleAutoWireTarget(ComponentReference reference) { - if (reference.getEndpointReferences().size() > 1 && reference.getBindings() != null && reference.getBindings().size() == 1) { - String uri = reference.getBindings().get(0).getURI(); - if (uri != null) { - if (uri.indexOf('/') > -1) { - // TODO: must be a way to avoid this fiddling - int i = uri.indexOf('/'); - String c = uri.substring(0, i); - String s = uri.substring(i+1); - uri = c + "#service(" + s + ")"; - } - for (EndpointReference er : reference.getEndpointReferences()) { - if (er.getTargetEndpoint() != null && uri.equals(er.getTargetEndpoint().getURI())) { - reference.getEndpointReferences().clear(); - reference.getEndpointReferences().add(er); - return; - } - } - } + private void setSingleAutoWireTarget(ComponentReference reference) { + if (reference.getEndpointReferences().size() > 1 && reference.getBindings() != null + && reference.getBindings().size() == 1) { + String uri = reference.getBindings().get(0).getURI(); + if (uri != null) { + if (uri.indexOf('/') > -1) { + // TODO: must be a way to avoid this fiddling + int i = uri.indexOf('/'); + String c = uri.substring(0, i); + String s = uri.substring(i + 1); + uri = c + "#service(" + s + ")"; + } + for (EndpointReference er : reference.getEndpointReferences()) { + if (er.getTargetEndpoint() != null && uri.equals(er.getTargetEndpoint().getURI())) { + reference.getEndpointReferences().clear(); + reference.getEndpointReferences().add(er); + return; + } + } + } } - } - + } + } // end class diff --git a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java index c25f46bc4f..c7693e135e 100644 --- a/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java +++ b/java/sca/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ModelBuilderImpl.java @@ -38,7 +38,7 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil private CompositeBuilder compositeCloneBuilder; private CompositeComponentTypeBuilderImpl compositeComponentTypeBuilder; private ComponentBuilderImpl componentBuilder; - + private BindingURIBuilderImpl bindingURIBuilder; private ComponentServiceBindingBuilderImpl componentServiceBindingBuilder; private ComponentReferenceBindingBuilderImpl componentReferenceBindingBuilder; @@ -46,23 +46,23 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil private EndpointReferenceBuilderImpl endpointReferenceBuilder; private ComponentReferencePromotionBuilderImpl componentReferencePromotionBuilder; private CompositePolicyBuilderImpl compositePolicyBuilder; - + /** * Constructs a new composite builder. * * @param registry the extension point registry */ public ModelBuilderImpl(ExtensionPointRegistry registry) { - + compositeIncludeBuilder = new CompositeIncludeBuilderImpl(); compositeCloneBuilder = new CompositeCloneBuilderImpl(); - + compositeComponentTypeBuilder = new CompositeComponentTypeBuilderImpl(registry); componentBuilder = new ComponentBuilderImpl(registry); - + compositeComponentTypeBuilder.setComponentBuilder(componentBuilder); componentBuilder.setComponentTypeBuilder(compositeComponentTypeBuilder); - + bindingURIBuilder = new BindingURIBuilderImpl(registry); componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(registry); componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(registry); @@ -77,33 +77,34 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil return "org.apache.tuscany.sca.assembly.builder.CompositeBuilder"; } - public Composite build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException { + public Composite build(Composite composite, Definitions definitions, Monitor monitor) + throws CompositeBuilderException { return build(composite, definitions, null, monitor); } public Composite build(Composite composite, - Definitions definitions, - Map<QName, List<String>> bindingBaseURIs, - Monitor monitor) throws CompositeBuilderException { + Definitions definitions, + Map<QName, List<String>> bindingBaseURIs, + Monitor monitor) throws CompositeBuilderException { try { // Collect and fuse includes. Copy all of the components // out of the included composite into the including composite // and discards the included composite composite = compositeIncludeBuilder.build(composite, definitions, monitor); - + // need to apply policy external attachment - + // Expand nested composites. Clone any composite model that // is acting as a component implementation and connects the cloned // model to the component implementation in question composite = compositeCloneBuilder.build(composite, definitions, monitor); - + // Process the implementation hierarchy by calculating the component type // for the top level implementation (composite). This has the effect of // recursively calculating component types and configuring the // components that depend on them - compositeComponentTypeBuilder.createComponentType(composite); + compositeComponentTypeBuilder.createComponentType(composite); // create the runtime model by updating the static model we have just // created. This involves things like creating @@ -124,9 +125,9 @@ public class ModelBuilderImpl implements CompositeBuilder, DeployedCompositeBuil endpointReferenceBuilder.build(composite, definitions, monitor); composite = componentReferencePromotionBuilder.build(composite, definitions, monitor); // move into the static build? composite = compositePolicyBuilder.build(composite, definitions, monitor); // the rest of the policy processing? - return composite; + return composite; } catch (Exception e) { throw new CompositeBuilderException("Exception while building model " + composite.getName(), e); - } + } } -} +} 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 94e1a6eed9..3ea0bd289b 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 @@ -66,7 +66,8 @@ abstract class ReferenceConfigurationUtil { if (definedMul != overridenMul) { switch (definedMul) { case ZERO_N: - return overridenMul == Multiplicity.ZERO_ONE || overridenMul == Multiplicity.ONE_ONE || overridenMul == Multiplicity.ONE_N; + return overridenMul == Multiplicity.ZERO_ONE || overridenMul == Multiplicity.ONE_ONE + || overridenMul == Multiplicity.ONE_N; case ONE_N: return overridenMul == Multiplicity.ONE_ONE; case ZERO_ONE: @@ -82,10 +83,10 @@ abstract class ReferenceConfigurationUtil { static boolean validateMultiplicityAndTargets(Multiplicity multiplicity, List<EndpointReference> endpointReferences) { // In some tests multiplicity is not set - if (multiplicity == null){ + if (multiplicity == null) { return true; } - + // Count targets int count = endpointReferences.size(); |