TUSCANY-3138 first tranche of changes to serialize service references in the form of an EndpointReference.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@796222 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bcbef540be
commit
9f264f4aeb
14 changed files with 359 additions and 387 deletions
|
@ -78,6 +78,7 @@ TUSCANY-3138 -->
|
|||
<module>scaclient-api</module>
|
||||
<module>scopes</module>
|
||||
<module>services</module>
|
||||
<module>service-reference</module>
|
||||
<module>wires</module>
|
||||
<module>policies</module>
|
||||
</modules>
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
}
|
|
@ -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
|
||||
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
|
||||
|
|
|
@ -115,13 +115,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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -240,134 +262,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());
|
||||
}
|
||||
}
|
||||
|
||||
public String toXMLString() throws IOException {
|
||||
if (reference != null) {
|
||||
if (clonedRef == null) {
|
||||
try {
|
||||
clonedRef = (RuntimeComponentReference)reference.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
// will not happen
|
||||
}
|
||||
}
|
||||
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 (toRemove != null) {
|
||||
clonedRef.getExtensions().remove(toRemove);
|
||||
}
|
||||
|
||||
// add the new reference parameter object
|
||||
clonedRef.getExtensions().add(refParams);
|
||||
}
|
||||
refParams.setCallbackID(callbackID);
|
||||
return ((CompositeActivatorImpl)compositeActivator).getCompositeContext().toXML(component, clonedRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return scdl;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 (parameters != null) {
|
||||
refParams = parameters;
|
||||
this.callbackID = parameters.getCallbackID();
|
||||
}
|
||||
|
||||
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 (endpointReference.getBinding() instanceof BindingBuilderExtension) {
|
||||
((BindingBuilderExtension)endpointReference.getBinding()).getBuilder().build(component, reference, endpointReference.getBinding(), null);
|
||||
}
|
||||
|
||||
this.proxyFactory = compositeActivator.getCompositeContext().getProxyFactory();
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue