in modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java [284:424]
private synchronized void resolve() throws Exception {
if ((scdl != null || xmlReader != null) && component == null && reference == null) {
ComponentContextHelper componentContextHelper = ComponentContextHelper.getCurrentComponentContextHelper();
if (componentContextHelper != null) {
this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator();
this.conversationManager = this.compositeActivator.getConversationManager();
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;
BusinessInterface businessInterfaceExt = null;
for (Object ext : reference.getExtensions()) {
if (ext instanceof ReferenceParameters) {
parameters = (ReferenceParameters)ext;
} else if (ext instanceof BusinessInterface) {
// this extension will always be present
businessInterfaceExt = (BusinessInterface)ext;
}
}
if (parameters != null) {
refParams = parameters;
this.callbackID = parameters.getCallbackID();
attachConversation(parameters.getConversationID());
}
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.getClass() == binding.getClass()) {
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);
}
}
ModelResolver resolver = ((ResolverExtension)ComponentContextHelper.getCurrentComponent()).getModelResolver();
componentContextHelper.resolveInterfaceContract(reference.getInterfaceContract(), resolver);
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.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. If we need to add code here to do this,
// we can resolve XSDs using the model resolver for the current component.
}
this.businessInterface = (Class<B>)javaInterface.getJavaClass();
} else {
// 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();
}
});
businessInterface = (Class<B>)classLoader.loadClass(businessInterfaceExt.getInterface());
reference.setReference(componentContextHelper.createReference(businessInterface));
}
componentContextHelper.resolveBinding(binding, resolver);
if (binding instanceof PolicySetAttachPoint) {
PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
List<PolicySet> policySets = policiedBinding.getPolicySets();
resolvePolicySets(policySets, resolver);
List<PolicySet> applicablePolicySets = policiedBinding.getApplicablePolicySets();
applicablePolicySets.addAll(policySets);
}
if (binding instanceof OperationsConfigurator) {
OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) {
List<PolicySet> policySets = confOp.getPolicySets();
resolvePolicySets(policySets, resolver);
List<PolicySet> applicablePolicySets = confOp.getApplicablePolicySets();
applicablePolicySets.addAll(policySets);
}
}
if (binding instanceof BindingBuilderExtension) {
((BindingBuilderExtension)binding).getBuilder().build(component, reference, binding, null);
}
this.proxyFactory = compositeActivator.getProxyFactory();
}
} else if (compositeActivator == null || proxyFactory == null) {
this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator();
if (this.compositeActivator != null) {
this.proxyFactory = this.compositeActivator.getProxyFactory();
}
}
}