private void validateReferenceMultiplicity(Composite composite, Component component, Monitor monitor) { for (ComponentReference componentReference : component.getReferences()) { if (!validateMultiplicity(componentReference.getMultiplicity(), componentReference.getEndpointReferences())) { if (componentReference.getEndpointReferences().isEmpty()) { if (!promoted && !componentReference.isForCallback() && !componentReference.isWiredByImpl()) { Monitor.error(monitor, this, "ReferenceWithoutTargets", composite.getName().toString(), componentReference.getName()); if (Boolean.TRUE.equals(componentReference.getAutowire())) { break; Messages.ASSEMBLY_VALIDATION, "TooManyReferenceTargets", componentReference.getName());
/** * Returns true if the reference has a callback */ private boolean hasCallback(EndpointReference endpointReference){ if (endpointReference.getReference().getInterfaceContract() == null || endpointReference.getReference().getInterfaceContract().getCallbackInterface() == null || endpointReference.getReference().getName().startsWith("$self$.")){ return false; } else { return true; } }
/** * ASM_5021: where a <reference/> of a <component/> has @autowire=true * and where the <reference/> has a <binding/> child element which * declares a single target service, the reference is wired only to * the single service identified by the <wire/> element */ private void setSingleAutoWireTarget(ComponentReference reference) { if (reference.getEndpointReferences().size() > 1 && reference.getBindings() != null && reference.getBindings().size() == 1) { String uri = reference.getBindings().get(0).getURI(); if (uri != null) { if (uri.indexOf('/') > -1) { // TODO: must be a way to avoid this fiddling int i = uri.indexOf('/'); String c = uri.substring(0, i); String s = uri.substring(i + 1); uri = c + "#service(" + s + ")"; } for (EndpointReference er : reference.getEndpointReferences()) { if (er.getTargetEndpoint() != null && uri.equals(er.getTargetEndpoint().getURI())) { reference.getEndpointReferences().clear(); reference.getEndpointReferences().add(er); return; } } } } }
/** * Helper method which obtains a list of targets for a reference * @param reference - Component reference * @return - the list of targets, which will be empty if there are no targets */ private List<ComponentService> getReferenceTargets(ComponentReference reference) { List<ComponentService> theTargets = reference.getTargets(); if (theTargets.isEmpty()) { // Component reference list of targets is empty, try the implementation reference if (reference.getReference() != null) { theTargets = reference.getReference().getTargets(); } // end if } // end if return theTargets; } // end method getReferenceTargets
ComponentReference componentReference, Monitor monitor) { Reference reference = componentReference.getReference(); if (!leafRef.isNonOverridable()) { leafRef.getEndpointReferences().clear(); for (EndpointReference epr : componentReference.getEndpointReferences()){ leafRef.getEndpointReferences().add(insertLocation, eprCopy); insertLocation++;
context.getMonitor().pushContext("Reference: " + reference.getName()); if (Boolean.TRUE.equals(reference.getAutowire()) && reference.getTargets().isEmpty()) { Multiplicity multiplicity = reference.getMultiplicity(); for (Component targetComponent : composite.getComponents()) { (reference.getEndpointReferences().size() != 0)) { break; if (reference.getInterfaceContract() == null || interfaceContractMapper.isCompatibleSubset(reference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { if (intentsMatch(reference.getRequiredIntents(), targetComponentService.getRequiredIntents())) { EndpointReference endpointRef = createEndpointRef(component, reference, false); endpointRef.setTargetEndpoint(createEndpoint(targetComponent, targetComponentService, true)); endpointRef.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND); reference.getEndpointReferences().add(endpointRef); if (reference.getEndpointReferences().size() == 0) { Monitor.error(context.getMonitor(), this, Messages.ASSEMBLY_VALIDATION, "NoComponentReferenceTarget", reference.getName()); composite.getName().toString(), component.getName(),
ComponentService service = endpoint.getService(); ComponentReference componentReference = assemblyFactory.createComponentReference(); componentReference.setName("$sca.client$." + service.getName()); componentReference.setCallback(service.getCallback()); componentReference.getTargets().add(service); componentReference.getPolicySets().addAll(service.getPolicySets()); componentReference.getRequiredIntents().addAll(service.getRequiredIntents()); componentReference.getBindings().add(endpoint.getBinding()); componentReference.setInterfaceContract(interfaceContract); componentReference.setMultiplicity(Multiplicity.ONE_ONE); componentReference.getEndpointReferences().add(endpointReference); ((RuntimeComponentReference)componentReference).setComponent((RuntimeComponent)component); ((RuntimeEndpointReference)endpointReference).bind(compositeContext);
if (source != null && source.isUnresolved()) { resolvedReference = componentReferences.get(source.getName()); if (resolvedReference != null) { wire.setSource(resolvedReference); } else { Monitor.warning(monitor, this, Messages.ASSEMBLY_VALIDATION, "WireSourceNotFound", source .getName()); if (resolvedReference.getInterfaceContract() == null || interfaceContractMapper .isCompatibleSubset(resolvedReference.getInterfaceContract(), resolvedService.getInterfaceContract())) { resolvedReference.getTargets().clear(); resolvedReference.getTargets().add(wire.getTarget()); } else { Monitor.warning(monitor, this, Messages.ASSEMBLY_VALIDATION, "WireIncompatibleInterface", source .getName(), target.getName());
if (reference.getInterfaceContract() != null && // can be null in unit tests reference.getInterfaceContract().getCallbackInterface() != null) { ComponentService callbackService = assemblyFactory.createComponentService(); callbackService.setForCallback(true); callbackService.setName(reference.getName()); try { InterfaceContract contract = (InterfaceContract)reference.getInterfaceContract().clone(); contract.setInterface(contract.getCallbackInterface()); contract.setCallbackInterface(null); Reference implReference = reference.getReference(); if (implReference != null) { if (((CompositeReference)implReference).getPromotedReferences().get(0).isUnresolved() == false){ String serviceName = ((CompositeReference)implReference).getPromotedReferences().get(0).getName(); ComponentService promotedService = ((CompositeReference)implReference).getPromotedComponents().get(0).getService(serviceName); "PromotedCallbackServiceNotFound", component.getName(), reference.getName(), ((CompositeReference)implReference).getPromotedComponents().get(0).getName(), serviceName); if (reference.getCallback() != null && reference.getCallback().getBindings().size() > 0) { callbackService.getBindings().addAll(reference.getCallback().getBindings()); } else if (reference.getBindings().size() > 0) { for (Binding binding : reference.getBindings()) {
public ComponentReference getReference(String name){ for (ComponentReference ref : getReferences()){ if (ref.getName().equals(name)){ return ref; } } return null; }
callbackReference.setForCallback(true); callbackReference.setName(service.getName()); callbackReference.setMultiplicity(Multiplicity.ZERO_N); try { InterfaceContract contract = (InterfaceContract)service.getInterfaceContract().clone(); contract.setCallbackInterface(null); contract.setNormalizedWSDLContract(null); callbackReference.setInterfaceContract(contract); } catch (CloneNotSupportedException e) { callbackReference.setReference(implReference); if (callbackReference.getBindings().isEmpty()) { callbackReference.getBindings().addAll(service.getCallback().getBindings()); } else { Binding referenceBinding = (Binding)serviceBinding.clone(); referenceBinding.setURI(null); callbackReference.getBindings().add(referenceBinding); } catch (CloneNotSupportedException e) {
public <B> TuscanyServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) throws IllegalArgumentException { for (ComponentReference ref : component.getReferences()) { if (referenceName.equals(ref.getName())) { Multiplicity multiplicity = ref.getMultiplicity(); if (multiplicity == Multiplicity.ZERO_N || multiplicity == Multiplicity.ONE_N) { throw new IllegalArgumentException("Reference " + referenceName + " has multiplicity " + multiplicity); } if (ref.getEndpointReferences().size() < 1) { return null; } TuscanyServiceReference<B> sr = getServiceReference(businessInterface, (RuntimeEndpointReference)getEndpointReference(ref)); if (sr == null) { throw new IllegalArgumentException("Reference " + referenceName + " is null"); } return sr; } } throw new IllegalArgumentException("[JCA80011] Reference not found: " + referenceName); }
if (componentReference != component.getReference(componentReference.getName())){ Monitor.error(monitor, this, "DuplicateComponentReferenceName", component.getName(), componentReference.getName()); if (componentReference.getReference() != null || componentReference.isForCallback()) { continue; Reference reference = component.getImplementation().getReference(componentReference.getName()); componentReference.setReference(reference); } else { Monitor.error(monitor, "ReferenceNotFoundForComponentReference", component.getName(), componentReference.getName());
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); endpointReference.setTargetEndpoint(endpoint); if (reference.getTargets().size() > 0){ endpoint.setURI(reference.getTargets().get(0).getName()); endpointReference.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND); endpointReference.setUnresolved(true); } else { endpoint.setUnresolved(false); endpoint.setBinding(reference.getBindings().get(0)); endpointReference.setStatus(EndpointReference.Status.RESOLVED_BINDING); endpointReference.setUnresolved(false);
for(EndpointReference epr : reference.getEndpointReferences()) { Endpoint targetEndpoint = epr.getTargetEndpoint(); if (targetEndpoint.isUnresolved()) { String referenceName = reference.getName(); JavascriptProxyFactory jsProxyFactory = javascriptProxyFactories.getProxyFactory(binding.getClass());
for (EndpointReference epr : componentReference.getEndpointReferences()) { else if ( (componentReference.getInterfaceContract() != null) && (isApplicableToSubject(document, appliesToSubjects, topComposite, componentReference.getInterfaceContract().getInterface(), ps))) continue; else if ( isApplicableToSubject(document, appliesToSubjects, topComposite, component, ps))
public InterfaceContract getComponentReferenceInterfaceContract() { resolve(); if (interfaceContract == null && reference != null) { interfaceContract = reference.getInterfaceContract(); } return interfaceContract; }
/** * Select an endpoint reference from the component reference * @param ref * @return */ private EndpointReference getEndpointReference(ComponentReference ref) { List<EndpointReference> eprs = ref.getEndpointReferences(); if (eprs.size() == 1) { // Return 1st one return eprs.get(0); } else { for (EndpointReference epr : eprs) { // Try to see if there is an EPR using binding.sca if (epr.getBinding().getType().equals(SCABinding.TYPE)) { return epr; } } return eprs.get(0); } }
componentReference.setName(getString(reader, NAME)); readMultiplicity(componentReference, reader); if (isSet(reader, AUTOWIRE)) { componentReference.setAutowire(getBoolean(reader, AUTOWIRE)); componentReference.setNonOverridable(Boolean.parseBoolean(nonOverridable)); componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL)); ComponentReference promotedReference = assemblyFactory.createComponentReference(); promotedReference.setUnresolved(true); promotedReference.setName(refName); compositeReference.getPromotedReferences().add(promotedReference); source.setUnresolved(true); source.setName(getURIString(reader, SOURCE)); wire.setSource(source);
/** * Implementation.web components currently don't use introspection to find the component type so unless an interface * is explicitly defined on a refererence with <interface.java> then the InterfaceContract will be null. This will * check for that and set the InterfaceContract from the Java class of the JSP tag. */ private void setInterfaceContract(RuntimeComponent component, Class<?> typeClass) throws InvalidInterfaceException { ComponentReference ref = component.getReference(name); if (ref.getInterfaceContract() == null) { ExtensionPointRegistry epr = component.getComponentContext().getExtensionPointRegistry(); FactoryExtensionPoint fep = epr.getExtensionPoint(FactoryExtensionPoint.class); JavaInterfaceFactory jif = fep.getFactory(JavaInterfaceFactory.class); JavaInterface javaIface = jif.createJavaInterface(typeClass); InterfaceContract interfaceContract = jif.createJavaInterfaceContract(); interfaceContract.setInterface(javaIface); ref.setInterfaceContract(interfaceContract); } } }