/** * 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); } }
/** * 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; } } } } }
/** * 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; } } } } }
/** * 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; } } } } }
/** * 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; } } } } }
/** * 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; } } } } }
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); }
public String createJavascriptReference(ComponentReference componentReference) throws IOException { EndpointReference epr = componentReference.getEndpointReferences().get(0); Endpoint targetEndpoint = epr.getTargetEndpoint(); if (targetEndpoint.isUnresolved()) { //force resolution and targetEndpoint binding calculations //by calling the getInvocationChain ((RuntimeEndpointReference) epr).getInvocationChains(); targetEndpoint = epr.getTargetEndpoint(); } Binding binding = targetEndpoint.getBinding(); URI targetURI = URI.create(binding.getURI()); String targetPath = targetURI.getPath(); return "tuscany.RestService(\"" + targetPath + "\")"; }
public String createJavascriptReference(ComponentReference componentReference) throws IOException { EndpointReference epr = componentReference.getEndpointReferences().get(0); Endpoint targetEndpoint = epr.getTargetEndpoint(); if (targetEndpoint.isUnresolved()) { //force resolution and targetEndpoint binding calculations //by calling the getInvocationChain ((RuntimeEndpointReference) epr).getInvocationChains(); targetEndpoint = epr.getTargetEndpoint(); } Binding binding = targetEndpoint.getBinding(); URI targetURI = URI.create(binding.getURI()); String targetPath = targetURI.getPath(); return "tuscany.AtomService(\"" + targetPath + "\")"; }
/** * @see ComponentContext#getServiceReferences(Class<B>, String) */ public <B> Collection<ServiceReference<B>> getServiceReferences(Class<B> businessInterface, String referenceName) { try { for (ComponentReference ref : component.getReferences()) { if (referenceName.equals(ref.getName())) { if (ref.getMultiplicity() == Multiplicity.ONE_ONE) throw new IllegalArgumentException("Reference " + referenceName + " is not a valid argument for getServiceReferences because it has a multiplicity of 1..1"); if (ref.getMultiplicity() == Multiplicity.ZERO_ONE) throw new IllegalArgumentException("Reference " + referenceName + " is not a valid argument for getServiceReferences because it has a multiplicity of 0..1"); ArrayList<ServiceReference<B>> serviceRefs = new ArrayList<ServiceReference<B>>(); for (EndpointReference endpointReference : ref.getEndpointReferences()) { RuntimeEndpointReference epr = (RuntimeEndpointReference)endpointReference; serviceRefs.add(getServiceReference(businessInterface, epr)); } return serviceRefs; } } throw new IllegalArgumentException("Reference not found: " + referenceName); } catch (IllegalArgumentException iae) { throw iae; } catch (ServiceRuntimeException e) { throw e; } catch (Exception e) { throw new ServiceRuntimeException(e.getMessage(), e); } }
for(EndpointReference epr : reference.getEndpointReferences()) { Endpoint targetEndpoint = epr.getTargetEndpoint(); if (targetEndpoint.isUnresolved()) {
for(EndpointReference epr : reference.getEndpointReferences()) { Endpoint targetEndpoint = epr.getTargetEndpoint(); if (targetEndpoint.isUnresolved()) {
private void validateReferenceMultiplicity(Composite composite, Component component, Monitor monitor) { for (ComponentReference componentReference : component.getReferences()) { if (!validateMultiplicity(componentReference.getMultiplicity(), componentReference.getEndpointReferences())) { if (componentReference.getEndpointReferences().isEmpty()) {
public ImplementationProvider createImplementationProvider(RuntimeComponent component, WebImplementation implementation) { ClientServlet clientServlet = new ClientServlet(); servletHost.addServletMapping(ClientServlet.SCRIPT_PATH, clientServlet); servletHost.addServletMapping(ClientServlet.SCRIPT_PATH + "/" + component.getName() + "/*", clientServlet); if (component.getReferences().size() > 0) { for (ComponentReference cr : component.getReferences()) { for (EndpointReference epr : cr.getEndpointReferences()) { clientServlet.addService((RuntimeEndpointReference)epr); } } } return new ImplementationProvider() { public Invoker createInvoker(RuntimeComponentService arg0, Operation arg1) { return null; } public void start() { } public void stop() { } public boolean supportsOneWayInvocation() { return false; } }; } }
endpointReference.setComponent(component); endpointReference.setReference(reference); reference.getEndpointReferences().add(endpointReference); endpointReference.setBinding(binding);
endpointReference.setComponent(component); endpointReference.setReference(reference); reference.getEndpointReferences().add(endpointReference); endpointReference.setBinding(binding);
componentReference.getEndpointReferences().add(endpointReference); ((RuntimeComponentReference)componentReference).setComponent((RuntimeComponent)component); ((RuntimeEndpointReference)endpointReference).bind(compositeContext);
componentReference.getEndpointReferences().add(endpointReference); ((RuntimeComponentReference)componentReference).setComponent((RuntimeComponent)component); ((RuntimeEndpointReference)endpointReference).bind(compositeContext);
componentReference.getEndpointReferences().add(endpointReference); ((RuntimeComponentReference)componentReference).setComponent((RuntimeComponent)component); ((RuntimeEndpointReference)endpointReference).bind(compositeContext);
private void populateLocalRegistry(Composite composite, DomainRegistry registry, BuilderContext context){ for (Component component : composite.getComponents()) { // recurse for composite implementations Implementation implementation = component.getImplementation(); if (implementation instanceof Composite) { populateLocalRegistry((Composite)implementation, registry, context); } // add all endpoints to the local registry for (ComponentService service : component.getServices()) { for (Endpoint endpoint : service.getEndpoints()){ registry.addEndpoint(endpoint); } } // add endpoint references that we want to match to the registry for (ComponentReference reference : component.getReferences()) { for (EndpointReference epr : reference.getEndpointReferences()){ if (epr.getStatus().equals(EndpointReference.Status.WIRED_TARGET_NOT_FOUND)|| epr.getStatus().equals(EndpointReference.Status.WIRED_TARGET_IN_BINDING_URI)){ registry.addEndpointReference(epr); } } } } }