From c055fee6db4a0be83184b67c7c8427fc53038b75 Mon Sep 17 00:00:00 2001 From: edwardsmj Date: Mon, 20 Jul 2009 21:54:02 +0000 Subject: Add support for 0..1 multiplicity references, as described in TUSCANY-3145 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@796034 13f79535-47bb-0310-9956-ffa450edef68 --- .../implementation/bpel/ode/EmbeddedODEServer.java | 2 +- .../bpel/ode/ODEEndpointReference.java | 96 ++++++++++++++++++++++ .../sca/implementation/bpel/ode/ODEEprContext.java | 75 +++++++++++++++++ .../bpel/ode/ODEExternalService.java | 2 + .../sca/implementation/bpel/ode/TuscanyPRC.java | 27 +++--- .../bpel/ode/TuscanyProcessConfImpl.java | 14 +++- 6 files changed, 195 insertions(+), 21 deletions(-) create mode 100644 java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java create mode 100644 java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java (limited to 'java/sca/modules/implementation-bpel-runtime/src/main') diff --git a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java index af0b1089e1..0772c88c4e 100644 --- a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java +++ b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java @@ -220,7 +220,7 @@ public class EmbeddedODEServer { _bpelServer.setDaoConnectionFactory(_daoCF); _bpelServer.setInMemDaoConnectionFactory(new BpelDAOConnectionFactoryImpl(_scheduler)); - //_bpelServer.setEndpointReferenceContext(eprContext); + _bpelServer.setEndpointReferenceContext( new ODEEprContext() ); _bpelServer.setMessageExchangeContext(new ODEMessageExchangeContext(this)); _bpelServer.setBindingContext(new ODEBindingContext()); _bpelServer.setScheduler(_scheduler); diff --git a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java new file mode 100644 index 0000000000..36d9ac1a20 --- /dev/null +++ b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEndpointReference.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel.ode; + +import org.apache.ode.bpel.iapi.Endpoint; +import org.apache.ode.bpel.iapi.EndpointReference; +import org.apache.ode.utils.DOMUtils; +import org.apache.tuscany.sca.assembly.Base; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Tuscany implementation of the ODE EndpointReference interface + * + */ +public class ODEEndpointReference implements EndpointReference { + + + private Document doc = DOMUtils.newDocument(); + private Element serviceref; + + /** + * Private constructor for the EndpointReference + */ + private ODEEndpointReference() { + super(); + } // end ODEEndpointReference() + + /** + * Add a new element to the EndpointReference + */ + private void addServiceRef() { + serviceref = doc.createElementNS(EndpointReference.SERVICE_REF_QNAME.getNamespaceURI(), + EndpointReference.SERVICE_REF_QNAME.getLocalPart()); + doc.appendChild(serviceref); + } // end method addServiceRef() + + /** + * Create an EndpointReference from an Endpoint object + * @param anEndpoint - the endpoint object + */ + public ODEEndpointReference( Endpoint anEndpoint ) { + this(); + addServiceRef(); + // If there is an endpoint for this reference (ie the reference is wired) + // then add an element to indicate this + String eprCount = anEndpoint.portName; + if( !"0".equals(eprCount) ) { + Element eprElement = doc.createElementNS( Base.SCA11_TUSCANY_NS, "EPR"); + serviceref.appendChild(eprElement); + } // end if + return; + } // end + + /** + * Create a new EndpointReference from an existing endpointElement, which is assumed + * to be of the form: + * + * + * + * + * @param endpointElement the endpointElement + */ + public ODEEndpointReference( Element endpointElement ) { + this(); + if( endpointElement != null ) { + // import the service-ref element into this EndpointReference, if the + // root element is a + if( endpointElement.getLocalName().equals("service-ref") ) { + doc.appendChild( doc.importNode(endpointElement, true) ); + } // end if + } // end if + return; + } // end + + public Document toXML() { + return doc; + } // end toXML() + +} diff --git a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java new file mode 100644 index 0000000000..2c5faef14d --- /dev/null +++ b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEEprContext.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.implementation.bpel.ode; + +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.ode.bpel.iapi.EndpointReference; +import org.apache.ode.bpel.iapi.EndpointReferenceContext; +import org.w3c.dom.Element; + +/** + * Implementation of the ODE EndpointReferenceContext interface, used by the ODE BPEL Engine + * to handle conversions of EndpointReferences at runtime. + * + * An ODE Endpoint reference relates to SCA Reference EndpointReferences (pointers to target + * services) and to BPEL PartnerLink elements and any associated BPEL process variables with + * type set to element="sref:service-ref" + * + */ +public class ODEEprContext implements EndpointReferenceContext { + + /** + * Converts an endpoint reference from its XML representation to another + * type of endpoint reference. + * + * @param targetType + * @param sourceEndpoint + * @return converted EndpointReference, being of targetType + */ + public EndpointReference convertEndpoint( QName targetType, + Element sourceEndpoint) { + // For the present, Tuscany only has one type of EndpointReference, so that the + // targetType parameter is of no significance. + return new ODEEndpointReference( sourceEndpoint ); + } // end method convertEndpoint + + public Map getConfigLookup(EndpointReference epr) { + // TODO Auto-generated method stub + return null; + } + + /** + * Resolve an end-point reference from its XML representation. The + * nature of the representation is determined by the integration + * layer. The BPEL engine uses this method to reconstruct + * {@link EndpointReference} objects that have been persisted in the + * database via {@link EndpointReference#toXML(javax.xml.transform.Result)} + * method. + * + * @param XML representation of the EPR + * @return reconstituted EPR object {@link EndpointReference} + */ + public EndpointReference resolveEndpointReference(Element epr) { + return new ODEEndpointReference( epr ); + } // end method resolveEndpointReference + +} // end class ODEEprContext diff --git a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java index 67e5eeb722..c24d703638 100644 --- a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java +++ b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEExternalService.java @@ -85,6 +85,8 @@ public class ODEExternalService { TuscanyPRC channel = (TuscanyPRC) partnerRoleMessageExchange.getChannel(); RuntimeComponent tuscanyRuntimeComponent = _server.getTuscanyRuntimeComponent(channel.getProcessName()); + // MJE 17/07/2009 - the get(0) here is totally bogus - if the component has >1 reference, this will fail + // miserably. We should be fetching the reference BY NAME - and this name must be stored in the PRC RuntimeComponentReference runtimeComponentReference = (RuntimeComponentReference)tuscanyRuntimeComponent.getReferences().get(0); RuntimeWire runtimeWire = diff --git a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java index b0539970ec..0de474a553 100644 --- a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java +++ b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyPRC.java @@ -25,9 +25,6 @@ import javax.xml.namespace.QName; import org.apache.ode.bpel.iapi.Endpoint; import org.apache.ode.bpel.iapi.EndpointReference; import org.apache.ode.bpel.iapi.PartnerRoleChannel; -import org.apache.ode.utils.DOMUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Element; /** * Tuscany Partner Role Channel for ODE Integration @@ -35,31 +32,29 @@ import org.w3c.dom.Element; * @version $Rev$ $Date$ */ public class TuscanyPRC implements PartnerRoleChannel { - private final QName processName; + private final QName processName; + private final Endpoint endpoint; public TuscanyPRC(QName processName, QName pid, PortType portType, Endpoint endpoint){ - this.processName = processName; + this.processName = processName; + this.endpoint = endpoint; } public QName getProcessName() { return this.processName; } + + public Endpoint getEndpoint() { + return this.endpoint; + } public void close() { } public EndpointReference getInitialEndpointReference() { - final Document doc = DOMUtils.newDocument(); - Element serviceref = doc.createElementNS(EndpointReference.SERVICE_REF_QNAME.getNamespaceURI(), - EndpointReference.SERVICE_REF_QNAME.getLocalPart()); - doc.appendChild(serviceref); - - return new EndpointReference() { - public Document toXML() { - return doc; - } - }; - } + + return new ODEEndpointReference( this.endpoint ); + } // end method getInitialEndpointReference } diff --git a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java index 89f3ad9568..48632bd1b7 100644 --- a/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java +++ b/java/sca/modules/implementation-bpel-runtime/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/TuscanyProcessConfImpl.java @@ -58,6 +58,7 @@ import org.apache.ode.bpel.iapi.ProcessConf; import org.apache.ode.bpel.iapi.ProcessState; import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.databinding.SimpleTypeMapper; @@ -271,20 +272,25 @@ public class TuscanyProcessConfImpl implements ProcessConf { /** * Returns a Map containing all the "invoke endpoints" - for which read "SCA references" * The map is keyed by partnerLink name and holds Endpoint objects - * + * 0..1 multiplicity references are not included in the returned Map (it is as if the reference is not there...) + * TODO deal with multiplicity 0..n and 1..n * TODO deal with service callbacks on bidirectional services */ public Map getInvokeEndpoints() { - //System.out.println("getInvokeEndpoints called"); if( invokeEndpoints == null ) { invokeEndpoints = new HashMap(); // Get a collection of the references - List theReferences = implementation.getReferences(); + List theReferences = component.getReferences(); + //List theReferences = implementation.getReferences(); // Create an endpoint for each reference, using the reference name as the "service" // name, combined with http://tuscany.apache.org to make a QName for( Reference reference : theReferences ) { + // Check that there is at least 1 configured SCA endpointReference for the reference, since it is + // possible for 0..1 multiplicity references to have no SCA endpointReferences configured + List eprs = reference.getEndpointReferences(); + String eprCount = Integer.toString( eprs.size() ); invokeEndpoints.put( reference.getName(), - new Endpoint( new QName( TUSCANY_NAMESPACE, reference.getName() ), "ReferencePort")); + new Endpoint( new QName( TUSCANY_NAMESPACE, reference.getName() ), eprCount)); } // end for } // end if return invokeEndpoints; -- cgit v1.2.3