diff options
Diffstat (limited to 'java/sca/modules')
13 files changed, 353 insertions, 382 deletions
diff --git a/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java new file mode 100644 index 0000000000..f0b203ce96 --- /dev/null +++ b/java/sca/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.monitor.Monitor; + +/** + * + */ +public class EndpointReferenceProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<EndpointReference> { + private final static String ENDPOINT = "endpointReference"; + private final static QName ENDPOINT_QNAME = new QName(Constants.SCA11_TUSCANY_NS, ENDPOINT); + + private ExtensionPointRegistry registry; + + public EndpointReferenceProcessor(ExtensionPointRegistry registry, + StAXArtifactProcessor extensionProcessor, + StAXAttributeProcessor extensionAttributeProcessor, + Monitor monitor) { + + super(modelFactories(registry), extensionProcessor, monitor); + this.registry = registry; + } + + /** + * Returns the model factory extension point to use. + * + * @param extensionPoints + * @return + */ + private static FactoryExtensionPoint modelFactories(ExtensionPointRegistry extensionPoints) { + return extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + } + + public QName getArtifactType() { + return ENDPOINT_QNAME; + } + + public EndpointReference read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + EndpointReference endpointReference = assemblyFactory.createEndpointReference(); + reader.nextTag(); + Object model = extensionProcessor.read(reader); + if (model instanceof Composite) { + Composite composite = (Composite)model; + Component component = composite.getComponents().get(0); + ComponentReference reference = component.getReferences().get(0); + Binding binding = reference.getBindings().get(0); + endpointReference.setComponent(component); + endpointReference.setReference(reference); + reference.getEndpointReferences().add(endpointReference); + endpointReference.setBinding(binding); + + // set up the EPR so that resolution will happen + // at wire creation time if needs be + Endpoint endpoint = assemblyFactory.createEndpoint(); + endpointReference.setTargetEndpoint(endpoint); + + if (reference.getTargets().size() > 0){ + // create a dummy endpoint with the URI set so that + // the endpoint registry will be consulted + endpoint.setUnresolved(true); + endpoint.setURI(reference.getTargets().get(0).getName()); + endpointReference.setStatus(EndpointReference.WIRED_TARGET_FOUND_BUT_NOT_MATCHED); + endpointReference.setUnresolved(true); + } else { + endpoint.setUnresolved(false); + endpoint.setBinding(reference.getBindings().get(0)); + endpointReference.setStatus(EndpointReference.RESOLVED_BINDING); + endpointReference.setUnresolved(false); + } + } + return endpointReference; + } + + public void write(EndpointReference model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + extensionProcessor.write(wrap(model), writer); + } + + private Composite wrap(EndpointReference endpointReference) { + try { + Composite composite = assemblyFactory.createComposite(); + composite.setName(ENDPOINT_QNAME); + composite.setLocal(false); + Component component = (Component)endpointReference.getComponent().clone(); + composite.getComponents().add(component); + component.getReferences().clear(); + component.getServices().clear(); + ComponentReference reference = (ComponentReference)endpointReference.getReference().clone(); + component.getReferences().add(reference); + reference.getBindings().clear(); + Binding binding = (Binding)endpointReference.getBinding().clone(); + reference.getBindings().add(binding); + //reference.setInterfaceContract(endpointReference.getInterfaceContract()); + if (endpointReference.getStatus() != EndpointReference.RESOLVED_BINDING){ + ComponentService service = assemblyFactory.createComponentService(); + service.setName(endpointReference.getTargetEndpoint().getURI()); + reference.getTargets().clear(); + reference.getTargets().add(service); + } + return composite; + } catch (CloneNotSupportedException e) { + return null; + } + } + + public Class<EndpointReference> getModelType() { + return EndpointReference.class; + } + + public void resolve(EndpointReference model, ModelResolver resolver) throws ContributionResolveException { + } +} diff --git a/java/sca/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor index 565fe12329..ee6538124e 100644 --- a/java/sca/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ b/java/sca/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -20,4 +20,5 @@ org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;qname=http://docs.oas org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#constrainingType,model=org.apache.tuscany.sca.assembly.ConstrainingType
org.apache.tuscany.sca.assembly.xml.CompositeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#composite,model=org.apache.tuscany.sca.assembly.Composite
org.apache.tuscany.sca.assembly.xml.SCABindingProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200903#binding.sca,model=org.apache.tuscany.sca.assembly.SCABinding
-org.apache.tuscany.sca.assembly.xml.EndpointProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.rmi#endpoint,model=org.apache.tuscany.sca.assembly.Endpoint
\ No newline at end of file +org.apache.tuscany.sca.assembly.xml.EndpointProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.rmi#endpoint,model=org.apache.tuscany.sca.assembly.Endpoint
+org.apache.tuscany.sca.assembly.xml.EndpointReferenceProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.rmi#endpointReference,model=org.apache.tuscany.sca.assembly.EndpointReference
diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java index 939afa40a8..c8518650fb 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java @@ -116,13 +116,6 @@ public interface CompositeActivator { void configureComponentContext(RuntimeComponent component); /** - * Resolve a component by URI in the domain - * @param componentURI - * @return - */ - Component resolve(String componentURI); - - /** * Set the domain composite * @param domainComposite */ diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java index 15c38db0e7..c213d9f8d2 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/impl/CompositeActivatorImpl.java @@ -355,6 +355,7 @@ public class CompositeActivatorImpl implements CompositeActivator { EndpointReference endpointReference = assemblyFactory.createEndpointReference(); endpointReference.setBinding(endpoint.getBinding()); endpointReference.setTargetEndpoint(endpoint); + endpointReference.setStatus(EndpointReference.WIRED_TARGET_FOUND_AND_MATCHED); // create the interface contract for the binding and service ends of the wire // that are created as forward only contracts @@ -840,7 +841,7 @@ public class CompositeActivatorImpl implements CompositeActivator { // Utility functions - // TODO - can we get rid of these? + // TODO - EPR - can we get rid of these? public CompositeContext getCompositeContext() { return compositeContext; @@ -854,6 +855,7 @@ public class CompositeActivatorImpl implements CompositeActivator { this.domainComposite = domainComposite; } + /* TODO - EPR - Resolved via registry now public Component resolve(String componentURI) { for (Composite composite : domainComposite.getIncludes()) { Component component = resolve(composite, componentURI); @@ -863,6 +865,7 @@ public class CompositeActivatorImpl implements CompositeActivator { } return null; } + public Component resolve(Composite composite, String componentURI) { for (Component component : composite.getComponents()) { @@ -880,5 +883,5 @@ public class CompositeActivatorImpl implements CompositeActivator { } return null; } - + */ } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceExt.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceExt.java deleted file mode 100644 index 597c3bc364..0000000000 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceExt.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.core.context; - -import java.io.Externalizable; -import java.io.IOException; - -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.runtime.RuntimeWire; -import org.oasisopen.sca.ServiceReference; - -/** - * Extended version of CallableReference - */ -public interface CallableReferenceExt<B> extends ServiceReference<B>, Externalizable { - /** - * @return - */ - RuntimeWire getRuntimeWire(); - - /** - * @return - * @throws IOException - */ - String toXMLString() throws IOException; - - /** - * @param callbackID - */ - void attachCallbackID(Object callbackID); - - /** - * @return - */ - EndpointReference getEndpointReference(); - - /** - * @return - */ - XMLStreamReader getXMLReader(); - -} diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceExt.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceExt.java index aa1e1de0f6..2a6940a8df 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceExt.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceExt.java @@ -19,11 +19,33 @@ package org.apache.tuscany.sca.core.context; +import java.io.Externalizable; +import java.io.IOException; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.runtime.RuntimeWire; import org.oasisopen.sca.ServiceReference; /** * Extended ServiceReference */ -public interface ServiceReferenceExt<B> extends CallableReferenceExt<B>, ServiceReference<B> { +public interface ServiceReferenceExt<B> extends ServiceReference<B>, Externalizable { + /** + * @return + */ + RuntimeWire getRuntimeWire(); + + /** + * @param callbackID + */ + void attachCallbackID(Object callbackID); + /** + * @return + */ + XMLStreamReader getXMLReader(); } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java index 8a13836dda..d331ea729d 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/CallableReferenceImpl.java @@ -21,36 +21,41 @@ package org.apache.tuscany.sca.core.context.impl; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.UUID; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentService; import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.assembly.OptimizableBinding; -import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension; +import org.apache.tuscany.sca.contribution.processor.ContributionReadException; +import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.core.assembly.CompositeActivator; import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; -import org.apache.tuscany.sca.core.assembly.impl.CompositeActivatorImpl; import org.apache.tuscany.sca.core.assembly.impl.ReferenceParametersImpl; import org.apache.tuscany.sca.core.assembly.impl.RuntimeWireImpl; -import org.apache.tuscany.sca.core.context.CallableReferenceExt; import org.apache.tuscany.sca.core.context.ComponentContextExt; import org.apache.tuscany.sca.core.context.CompositeContext; +import org.apache.tuscany.sca.core.context.ServiceReferenceExt; import org.apache.tuscany.sca.core.factory.ObjectCreationException; import org.apache.tuscany.sca.core.invocation.ProxyFactory; import org.apache.tuscany.sca.interfacedef.Interface; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; @@ -59,14 +64,16 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; import org.oasisopen.sca.ServiceRuntimeException; /** - * Base class for implementations of service and callback references. + * The old base class for implementations of service and callback references. We have maintained + * this in Tuscany 2.x for the time being even though SCA 1.1 only defines service references and + * not callable reference * * @version $Rev$ $Date$ * @param <B> the type of the business interface */ -public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { +public class CallableReferenceImpl<B> implements ServiceReferenceExt<B> { static final long serialVersionUID = -521548304761848325L; - protected transient CompositeActivator compositeActivator; + protected transient ProxyFactory proxyFactory; protected transient Class<B> businessInterface; protected transient Object proxy; @@ -83,8 +90,14 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { private transient ReferenceParameters refParams; private transient XMLStreamReader xmlReader; + protected transient CompositeActivator compositeActivator; + private ExtensionPointRegistry registry; private FactoryExtensionPoint modelFactories; protected RuntimeAssemblyFactory assemblyFactory; + private StAXArtifactProcessorExtensionPoint staxProcessors; + private StAXArtifactProcessor<EndpointReference> staxProcessor; + private XMLInputFactory xmlInputFactory; + private XMLOutputFactory xmlOutputFactory; /* * Public constructor for Externalizable serialization/deserialization @@ -96,6 +109,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { /* * Public constructor for use by XMLStreamReader2CallableReference */ + // TODO - EPR - Is this required public CallableReferenceImpl(XMLStreamReader xmlReader) throws Exception { this.xmlReader = xmlReader; resolve(); @@ -112,11 +126,9 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { this.component = component; this.reference = reference; this.endpointReference = endpointReference; - - ExtensionPointRegistry registry = compositeActivator.getCompositeContext().getExtensionPointRegistry(); - this.modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); - + this.compositeActivator = compositeActivator; + + getExtensions(); // FIXME: The SCA Specification is not clear how we should handle multiplicity // for CallableReference @@ -124,7 +136,7 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { // TODO - EPR - If no endpoint reference specified assume the first one // This will happen when a self reference is created in which case the - // the reference should only have on endpointReference so use that + // the reference should only have one endpointReference so use that if (this.reference.getEndpointReferences().size() == 0){ throw new ServiceRuntimeException("The reference " + reference.getName() + " in component " + component.getName() + " has no endpoint references"); @@ -143,6 +155,16 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { this.compositeActivator = compositeActivator; initCallbackID(); } + + private void getExtensions() { + this.registry = compositeActivator.getCompositeContext().getExtensionPointRegistry(); + this.modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = (RuntimeAssemblyFactory)modelFactories.getFactory(AssemblyFactory.class); + this.xmlInputFactory = modelFactories.getFactory(XMLInputFactory.class); + this.xmlOutputFactory = modelFactories.getFactory(XMLOutputFactory.class); + this.staxProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + this.staxProcessor = staxProcessors.getProcessor(EndpointReference.class); + } public CallableReferenceImpl(Class<B> businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) { this.proxyFactory = proxyFactory; @@ -241,134 +263,6 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { } /** - * @see java.io.Externalizable#readExternal(java.io.ObjectInput) - */ - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - final boolean hasSCDL = in.readBoolean(); - if (hasSCDL) { - this.scdl = in.readUTF(); - } else { - this.scdl = null; - } - } - - /** - * @throws IOException - */ - // TODO - EPR all needs sorting out for endpoint references - - private synchronized void resolve() throws Exception { - if ((scdl != null || xmlReader != null) && component == null && reference == null) { - CompositeContext componentContextHelper = CompositeContext.getCurrentCompositeContext(); - if (componentContextHelper != null) { - this.compositeActivator = CompositeContext.getCurrentCompositeActivator(); - Component c; - if (xmlReader != null) { - c = componentContextHelper.fromXML(xmlReader); - xmlReader = null; // OK to GC this now - } else { - c = componentContextHelper.fromXML(scdl); - scdl = null; // OK to GC this now - } - this.component = (RuntimeComponent)c; - compositeActivator.configureComponentContext(this.component); - this.reference = (RuntimeComponentReference)c.getReferences().get(0); - this.reference.setComponent(this.component); - clonedRef = reference; - ReferenceParameters parameters = null; - for (Object ext : reference.getExtensions()) { - if (ext instanceof ReferenceParameters) { - parameters = (ReferenceParameters)ext; - break; - } - } - if (parameters != null) { - refParams = parameters; - this.callbackID = parameters.getCallbackID(); - } - - // TODO - EPR all needs sorting out for endpoint references - for (Binding binding : reference.getBindings()) { - if (binding instanceof OptimizableBinding) { - // Resolve the Component - final String bindingURI = binding.getURI(); - final Component targetComponent = resolveComponentURI(bindingURI); - - // Find the Service - ComponentService targetService = resolveServiceURI(bindingURI, targetComponent); - - // if the target service is a promoted service then find the - // service it promotes - if ((targetService != null) && (targetService.getService() instanceof CompositeService)) { - CompositeService compositeService = (CompositeService)targetService.getService(); - // Find the promoted component service - ComponentService promotedComponentService = getPromotedComponentService(compositeService); - if (promotedComponentService != null && !promotedComponentService.isUnresolved()) { - targetService = promotedComponentService; - } - } - - OptimizableBinding optimizableBinding = (OptimizableBinding)binding; - optimizableBinding.setTargetComponent(targetComponent); - optimizableBinding.setTargetComponentService(targetService); - if (targetService != null) { - for (Binding serviceBinding : targetService.getBindings()) { - if (serviceBinding.getType().equals(binding.getType())) { - optimizableBinding.setTargetBinding(serviceBinding); - break; - } - } - } - } - } -/* - // FIXME: The SCA Specification is not clear how we should handle multiplicity - // for CallableReference - if (binding == null) { - binding = reference.getBinding(SCABinding.class); - if (binding == null) { - binding = reference.getBindings().get(0); - } - } -*/ - - Interface i = reference.getInterfaceContract().getInterface(); - if (i instanceof JavaInterface) { - JavaInterface javaInterface = (JavaInterface)i; - if (javaInterface.isUnresolved()) { - // Allow privileged access to get ClassLoader. Requires RuntimePermission in - // security policy. - ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { - public ClassLoader run() { - return Thread.currentThread().getContextClassLoader(); - } - }); - javaInterface.setJavaClass(classLoader.loadClass(javaInterface.getName())); - compositeActivator.getCompositeContext().getJavaInterfaceFactory() - .createJavaInterface(javaInterface, javaInterface.getJavaClass()); - //FIXME: If the interface needs XSDs to be loaded (e.g., for static SDO), - // this needs to be done here. We usually search for XSDs in the current - // contribution at resolve time. Is it possible to locate the current - // contribution at runtime? - } - this.businessInterface = (Class<B>)javaInterface.getJavaClass(); - } -/* - if (binding instanceof BindingBuilderExtension) { - ((BindingBuilderExtension)binding).getBuilder().build(component, reference, binding, null); - } -*/ - this.proxyFactory = compositeActivator.getCompositeContext().getProxyFactory(); - } - } else { - this.compositeActivator = CompositeContext.getCurrentCompositeActivator(); - if (this.compositeActivator != null) { - this.proxyFactory = this.compositeActivator.getCompositeContext().getProxyFactory(); - } - } - } - - /** * Follow a service promotion chain down to the inner most (non composite) * component service. * @@ -396,12 +290,22 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { } } + // ============ WRITE AND READ THE REFERENCE TO EXTERNAL XML ======================== + /** + * write the reference to a stream + * * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) */ public void writeExternal(ObjectOutput out) throws IOException { try { - final String xml = toXMLString(); + String xml = null; + if (scdl == null){ + xml = toXMLString(); + } else { + xml = scdl; + } + if (xml == null) { out.writeBoolean(false); } else { @@ -412,41 +316,124 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { // e.printStackTrace(); throw new IOException(e.toString()); } + } + + /** + * write the endpoint reference into an xml string + */ + public String toXMLString() throws IOException, XMLStreamException, ContributionWriteException{ + StringWriter writer = new StringWriter(); + XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(writer); + staxProcessor.write(endpointReference, streamWriter); + return writer.toString(); + } + + /** + * Read the reference from a stream + * + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) + */ + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + final boolean hasSCDL = in.readBoolean(); + if (hasSCDL) { + this.scdl = in.readUTF(); + } else { + this.scdl = null; + } + } + + /** + * Read xml string into the endpoint reference + */ + public void fromXMLString() throws IOException, XMLStreamException, ContributionReadException { + + XMLStreamReader streamReader = xmlReader; + + if (scdl != null ){ + Reader reader = new StringReader(scdl); + + if (xmlInputFactory == null){ + // this is a reference being read from a external stream + // so set up enough of the reference in order to resolved the + // xml being read + CompositeContext componentContextHelper = CompositeContext.getCurrentCompositeContext(); + this.compositeActivator = CompositeContext.getCurrentCompositeActivator(); + getExtensions(); + } + + streamReader = xmlInputFactory.createXMLStreamReader(reader); + } + + endpointReference = staxProcessor.read(streamReader); + + // ok to GC + xmlReader = null; + scdl = null; } - - public String toXMLString() throws IOException { - if (reference != null) { - if (clonedRef == null) { - try { - clonedRef = (RuntimeComponentReference)reference.clone(); - } catch (CloneNotSupportedException e) { - // will not happen + + /** + * @throws IOException + */ + private synchronized void resolve() throws Exception { + if ((scdl != null || xmlReader != null) && component == null && reference == null) { + fromXMLString(); + + this.component = (RuntimeComponent)endpointReference.getComponent(); + compositeActivator.configureComponentContext(this.component); + + this.reference = (RuntimeComponentReference)endpointReference.getReference(); + this.reference.setComponent(this.component); + clonedRef = reference; + + ReferenceParameters parameters = null; + for (Object ext : reference.getExtensions()) { + if (ext instanceof ReferenceParameters) { + parameters = (ReferenceParameters)ext; + break; } } - if (refParams == null) { - refParams = new ReferenceParametersImpl(); - - // remove any existing reference parameters from the clone - Object toRemove = null; - for (Object extension : clonedRef.getExtensions()) { - if (extension instanceof ReferenceParameters) { - toRemove = extension; - } - } + + if (parameters != null) { + refParams = parameters; + this.callbackID = parameters.getCallbackID(); + } - if (toRemove != null) { - clonedRef.getExtensions().remove(toRemove); + Interface i = reference.getInterfaceContract().getInterface(); + if (i instanceof JavaInterface) { + JavaInterface javaInterface = (JavaInterface)i; + if (javaInterface.isUnresolved()) { + // Allow privileged access to get ClassLoader. Requires RuntimePermission in + // security policy. + ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { + public ClassLoader run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + javaInterface.setJavaClass(classLoader.loadClass(javaInterface.getName())); + compositeActivator.getCompositeContext().getJavaInterfaceFactory() + .createJavaInterface(javaInterface, javaInterface.getJavaClass()); + //FIXME: If the interface needs XSDs to be loaded (e.g., for static SDO), + // this needs to be done here. We usually search for XSDs in the current + // contribution at resolve time. Is it possible to locate the current + // contribution at runtime? } - - // add the new reference parameter object - clonedRef.getExtensions().add(refParams); + this.businessInterface = (Class<B>)javaInterface.getJavaClass(); } - refParams.setCallbackID(callbackID); - return ((CompositeActivatorImpl)compositeActivator).getCompositeContext().toXML(component, clonedRef); + + if (endpointReference.getBinding() instanceof BindingBuilderExtension) { + ((BindingBuilderExtension)endpointReference.getBinding()).getBuilder().build(component, reference, endpointReference.getBinding(), null); + } + + this.proxyFactory = compositeActivator.getCompositeContext().getProxyFactory(); } else { - return scdl; - } + this.compositeActivator = CompositeContext.getCurrentCompositeActivator(); + if (this.compositeActivator != null) { + this.proxyFactory = this.compositeActivator.getCompositeContext().getProxyFactory(); + } + } } + + // ================================================================================== /** * Create a callback id @@ -467,111 +454,8 @@ public class CallableReferenceImpl<B> implements CallableReferenceExt<B> { return parameters; } - // TODO - EPR - needs sorting out for new endpoint references - public EndpointReference getEndpointReference() { - try { - resolve(); - - // Use the interface contract of the reference on the component type - Reference componentTypeRef = reference.getReference(); - InterfaceContract sourceContract = - componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract(); - sourceContract = sourceContract.makeUnidirectional(false); - - EndpointReference epr = assemblyFactory.createEndpointReference(); - epr.setComponent(component); - epr.setReference(reference); - //epr.setBinding(binding); - epr.setInterfaceContract(sourceContract); - - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpoint.setService(component.getServices().get(0)); - epr.setTargetEndpoint(endpoint); - - return epr; - } catch (Exception e) { - throw new ServiceRuntimeException(e); - } - } - public XMLStreamReader getXMLReader() { return xmlReader; } - /** - * Resolves the specified URI to a Component using the compositeActivator. - * There are two cases that we need to handle: - * <ul> - * <li>URI containing just Composite name(s) (i.e. no Service name specified) - * <li>URI containing Composite name(s) and a Service Name - * </ul> - * - * @param componentURI The URI of the Component to resolve - * @return The Component for the specified URI or null if not founds - */ - protected Component resolveComponentURI(String componentURI) { - // If the URI has come from a binding, it may well start with a '/'. We will need - // to remove this so we can match it to the composite names. - if (componentURI.startsWith("/")) { - componentURI = componentURI.substring(1); - } - - // First assume that we are dealing with a Component URI without a Service Name - Component component = compositeActivator.resolve(componentURI); - if (component != null) { - return component; - } - - // Perhaps we have a ComponentURI that has a ServiceName on the end of it - final int index = componentURI.lastIndexOf('/'); - if (index > -1) { - componentURI = componentURI.substring(0, index); - return compositeActivator.resolve(componentURI); - } - - // We could not resolve the Component URI - return null; - } - - /** - * Examines the Services on the specified Component and returns the Service that matches the - * specified Binding URI. - * - * @param bindingURI The Binding URI to resolve on the Component - * @param targetComponent The Component containing the Services - * @return The Service with the specified serviceName or null if no such Service found. - */ - protected ComponentService resolveServiceURI(String bindingURI, Component targetComponent) { - - ComponentService targetService = null; - - if (targetComponent != null) { - if (bindingURI.startsWith("/")) { - bindingURI = bindingURI.substring(1); - } - - final String componentURI = targetComponent.getURI(); - final String serviceName; - if (componentURI.equals(bindingURI)) { - // No service specified - serviceName = ""; - } else { - // Get the Service name from the Binding URI - serviceName = bindingURI.substring(componentURI.length() + 1); - } - - if ("".equals(serviceName)) { - targetService = CompositeContext.getSingleService(targetComponent); - } else { - for (ComponentService service : targetComponent.getServices()) { - if (service.getName().equals(serviceName)) { - targetService = service; - break; - } - } - } - } - - return targetService; - } } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java index 784eeb76b1..a6c8bbd29f 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ComponentContextImpl.java @@ -295,7 +295,7 @@ public class ComponentContextImpl implements ComponentContextExt { RuntimeComponentReference ref = (RuntimeComponentReference)createSelfReference(component, service, businessInterface); ref.setComponent(component); - return new CallableReferenceImpl<B>(businessInterface, component, ref, null, proxyFactory, + return new ServiceReferenceImpl<B>(businessInterface, component, ref, null, proxyFactory, compositeActivator); } catch (Exception e) { throw new ServiceRuntimeException(e); @@ -348,7 +348,8 @@ public class ComponentContextImpl implements ComponentContextExt { .createEndpointReference(); endpointReference.setComponent(component); endpointReference.setReference(componentReference); - endpointReference.setUnresolved(false); + endpointReference.setUnresolved(false); + endpointReference.setStatus(EndpointReference.WIRED_TARGET_FOUND_BUT_NOT_MATCHED); // create endpoint. Endpoint endpoint = assemblyFactory.createEndpoint(); diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java index 24709712be..fed984cef6 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/context/impl/ServiceReferenceImpl.java @@ -34,7 +34,7 @@ import org.apache.tuscany.sca.runtime.RuntimeWire; * @version $Rev$ $Date$ * @param <B> the type of the business interface */ -public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> implements ServiceReferenceExt<B> { +public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> { private static final long serialVersionUID = 6763709434194361540L; protected transient Object callback; @@ -49,6 +49,7 @@ public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> implements /* * Public constructor for use by XMLStreamReader2CallableReference */ + // TODO - EPR - is this required public ServiceReferenceImpl(XMLStreamReader xmlReader) throws Exception { super(xmlReader); } @@ -78,30 +79,4 @@ public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> implements CompositeActivator compositeActivator) { super(businessInterface, component, reference, endpointReference, proxyFactory, compositeActivator); } - -// public void setCallbackID(Object callbackID) { -// this.callbackID = callbackID; -// } -// -// public Object getCallback() { -// return callback; -// } - -/* TODO - EPR - not required in OASIS - @Override - protected ReferenceParameters getReferenceParameters() { - ReferenceParameters parameters = super.getReferenceParameters(); - if (callback != null) { - if (callback instanceof ServiceReference) { - EndpointReference callbackRef = ((CallableReferenceExt)callback).getEndpointReference(); - parameters.setCallbackReference(callbackRef); - } else { - EndpointReference callbackRef = getRuntimeWire().getSource().getCallbackEndpoint(); - parameters.setCallbackReference(callbackRef); - parameters.setCallbackObjectID(callback); - } - } - return parameters; - } -*/ } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java index ced3c07d14..0bf7b3554e 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java @@ -65,7 +65,7 @@ public class CglibProxyFactory implements ProxyFactory { enhancer.setSuperclass(interfaze); enhancer.setCallback(new CglibMethodInterceptor<T>(callableReference)); Object proxy = enhancer.create(); - ((CallableReferenceImpl)callableReference).setProxy(proxy); + ((ServiceReferenceImpl)callableReference).setProxy(proxy); return interfaze.cast(proxy); } diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java index 56c5d813ab..00bb51163a 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKCallbackInvocationHandler.java @@ -61,7 +61,8 @@ public class JDKCallbackInvocationHandler extends JDKInvocationHandler { // TODO - EPR - not required for OASIS //initConversational(wire); - setEndpoint(((ServiceReferenceImpl)callableReference).getEndpointReference().getTargetEndpoint()); +// TODO - EPR - Fix up callbacks now callable reference has gone +// setEndpoint(((ServiceReferenceImpl)callableReference).getEndpointReference().getTargetEndpoint()); InvocationChain chain = getInvocationChain(method, wire); if (chain == null) { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java index 6d24818b73..b0788bd4b2 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKInvocationHandler.java @@ -29,7 +29,7 @@ import java.util.Map; import org.apache.tuscany.sca.assembly.Endpoint; import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.core.context.CallableReferenceExt; +import org.apache.tuscany.sca.core.context.ServiceReferenceExt; import org.apache.tuscany.sca.core.factory.InstanceWrapper; import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; import org.apache.tuscany.sca.core.scope.TargetResolutionException; @@ -74,7 +74,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { this.callableReference = callableReference; if (callableReference != null) { this.businessInterface = callableReference.getBusinessInterface(); - this.wire = ((CallableReferenceExt<?>)callableReference).getRuntimeWire(); + this.wire = ((ServiceReferenceExt<?>)callableReference).getRuntimeWire(); if (wire != null) { init(wire); } @@ -111,6 +111,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { // } } + /* TODO - EPR - Not reqiured for OASIS protected Object getCallbackObject() { if (callableReference != null && callableReference instanceof ServiceReference) { return ((ServiceReference)callableReference).getService(); @@ -118,6 +119,7 @@ public class JDKInvocationHandler implements InvocationHandler, Serializable { return null; } } + */ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Object.class == method.getDeclaringClass()) { diff --git a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java index 5e8ce3e45b..d7adec292d 100644 --- a/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java +++ b/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/impl/JDKProxyFactory.java @@ -67,7 +67,7 @@ public class JDKProxyFactory implements ProxyFactory { } }); Object proxy = CachedProxy.newProxyInstance(cl, new Class[] {interfaze}, handler); - ((CallableReferenceImpl)callableReference).setProxy(proxy); + ((ServiceReferenceImpl)callableReference).setProxy(proxy); return interfaze.cast(proxy); } |