/** * Generates the javascript proxy for a service. * * @param service * the service for which generation is performed */ public static void generateServiceProxy(final ComponentService service) { JavascriptGenerator.javascript.append(JavascriptGenerator.COMPONENT_CONTEXT + "." + service.getName() + " = new Object();\n"); }
public ComponentService getService(String name) { for (ComponentService service : getServices()) { if (service.getName().equals(name)) { return service; } } return null; }
public ComponentService getService(String name) { for (ComponentService service : getServices()) { if (service.getName().equals(name)) { return service; } } return null; }
public boolean isAsyncInvocation() { if (service != null && service.getName().endsWith("_asyncCallback")) { // this is a response service at the reference component so don't create a // response reference. return false; } // end if for (Intent intent : getRequiredIntents()) { if (intent.getName().getLocalPart().equals("asyncInvocation")) { return true; } } return false; }
public String getURI() { if (uri == null) { if (component != null && service != null && binding != null) { String bindingName = binding.getName(); if (bindingName == null) { bindingName = service.getName(); } uri = component.getURI() + "#service-binding(" + service.getName() + "/" + bindingName + ")"; } else if (component != null && service != null) { uri = component.getURI() + "#service(" + service.getName() + ")"; } else if (component != null) { uri = component.getURI(); } } return uri; }
public boolean isAsyncInvocation() { if (service != null && service.getName().endsWith("_asyncCallback")) { // this is a response service at the reference component so don't create a // response reference. return false; } // end if for (Intent intent : getRequiredIntents()) { if (intent.getName().getLocalPart().equals("asyncInvocation")) { return true; } } return false; }
public String getURI() { if (uri == null) { if (component != null && service != null && binding != null) { String bindingName = binding.getName(); if (bindingName == null) { bindingName = service.getName(); } uri = component.getURI() + "#service-binding(" + service.getName() + "/" + bindingName + ")"; } else if (component != null && service != null) { uri = component.getURI() + "#service(" + service.getName() + ")"; } else if (component != null) { uri = component.getURI(); } } return uri; }
/** * Generates the method inside the service proxy for the specified * operation. * * @param service * the service containing the operation * @param operation * the operation */ public static void generateMethodProxy(final ComponentService service, final Operation operation) { JavascriptGenerator.javascript.append(JavascriptGenerator.COMPONENT_CONTEXT + "." + service.getName() + "." + operation.getName() + " = function("); for (int i = 0; i < operation.getInputType().getLogical().size(); i++) { JavascriptGenerator.javascript.append("p" + i + ", "); } JavascriptGenerator.javascript.append("callbackMethod) {\n"); // send method argumets as JSON array JavascriptGenerator.javascript.append(" var params = [];\n"); for (int i = 0; i < operation.getInputType().getLogical().size(); i++) { JavascriptGenerator.javascript.append(" params.push(p" + i + ");\n"); } JavascriptGenerator.javascript.append(" " + JavascriptGenerator.TUSCANY_COMET + ".callAsync('" + service.getName() + "/" + operation.getName() + "', $.toJSON(params), callbackMethod);\n"); JavascriptGenerator.javascript.append("}\n"); }
/** * @param component */ public static ComponentService getSingleService(Component component) { ComponentService targetService; List<ComponentService> services = component.getServices(); List<ComponentService> regularServices = new ArrayList<ComponentService>(); for (ComponentService service : services) { if (service.isForCallback()) { continue; } String name = service.getName(); if (!name.startsWith("$") || name.startsWith("$dynamic$")) { regularServices.add(service); } } if (regularServices.size() == 0) { throw new ServiceRuntimeException("No service is declared on component " + component.getURI()); } if (regularServices.size() != 1) { throw new ServiceRuntimeException("More than one service is declared on component " + component.getURI() + ". Service name is required to get the service."); } targetService = regularServices.get(0); return targetService; }
public String getServiceName() { Message msgContext = ThreadMessageContext.getMessageContext(); if (msgContext != null && msgContext.getTo() != null){ return msgContext.getTo().getService().getName(); } else { // message in thread context could be null (or the default message where to == null) // if the user has spun up a new thread inside their component implementation return null; } }
@Override public int complete(final String buffer, final int cursor, final List clist) { if (shell.getNode() != null) { List<String> services = new ArrayList<String>(); DomainRegistry reg = ((NodeImpl)shell.getNode()).getEndpointRegistry(); for (Endpoint endpoint : reg.getEndpoints()) { services.add(endpoint.getComponent().getURI() + "/" + endpoint.getService().getName()); } setCandidateStrings(services.toArray(new String[services.size()])); } return super.complete(buffer, cursor, clist); }
@Override public int complete(final String buffer, final int cursor, final List clist) { if (shell.getNode() != null) { List<String> services = new ArrayList<String>(); DomainRegistry reg = ((NodeImpl)shell.getNode()).getEndpointRegistry(); for (Endpoint endpoint : reg.getEndpoints()) { services.add(endpoint.getComponent().getURI() + "/" + endpoint.getService().getName()); } setCandidateStrings(services.toArray(new String[services.size()])); } return super.complete(buffer, cursor, clist); }
public synchronized Endpoint getEndpoint(String uri) { for (Endpoint ep : endpoints) { String epURI = ep.getComponent().getURI() + "#" + ep.getService().getName() + "/" + ep.getBinding().getName(); if (epURI.equals(uri)) { return ep; } if (ep.getBinding().getName() == null || ep.getBinding().getName().equals(ep.getService().getName())) { epURI = ep.getComponent().getURI() + "#" + ep.getService().getName(); if (epURI.equals(uri)) { return ep; } } } return null; }
/** * Follow a service promotion chain down to the inner most (non composite) * component service. * * @param topCompositeService * @return */ public ComponentService getPromotedComponentService(CompositeService compositeService) { ComponentService componentService = compositeService.getPromotedService(); if (componentService != null) { Service service = componentService.getService(); if (componentService.getName() != null && service instanceof CompositeService) { // Continue to follow the service promotion chain return getPromotedComponentService((CompositeService)service); } else { // Found a non-composite service return componentService; } } else { // No promoted service return null; } }
/** * Follow a service promotion chain down to the inner most (non composite) * component service. * * @param topCompositeService * @return */ private ComponentService getPromotedComponentService(CompositeService compositeService) { ComponentService componentService = compositeService.getPromotedService(); if (componentService != null) { Service service = componentService.getService(); if (componentService.getName() != null && service instanceof CompositeService) { // Continue to follow the service promotion chain return getPromotedComponentService((CompositeService)service); } else { // Found a non-composite service return componentService; } } else { // No promoted service return null; } }
/** * Select an endpoint reference from the component reference * @param ref * @return */ private Endpoint getEndpoint(ComponentService service, String bindingName) { if (bindingName == null) { // The default binding name is the name of the promoted service bindingName = getPromotedService(service).getName(); } Endpoint returnEp = null; List<Endpoint> eps = service.getEndpoints(); for (Endpoint ep : eps) { Binding binding = ep.getBinding(); if (bindingName.equals(binding.getName()) || binding.getName() == null) { returnEp = ep; break; } } //TUSCANY-3543 if (returnEp == null) { returnEp = eps.get(0); } return returnEp; }
boolean services() throws IOException { if (getNode() == null) { return true; } DomainRegistry reg = ((NodeImpl)getNode()).getEndpointRegistry(); for (Endpoint endpoint : reg.getEndpoints()) { out.println(endpoint.getComponent().getURI() + "/" + endpoint.getService().getName()); for (Binding b : endpoint.getService().getBindings()) { if (!SCABinding.TYPE.equals(b.getType())) { out.println(" " + b.getType().getLocalPart() + " " + b.getURI()); } } } return true; }
boolean services() throws IOException { if (getNode() == null) { return true; } DomainRegistry reg = ((NodeImpl)getNode()).getEndpointRegistry(); for (Endpoint endpoint : reg.getEndpoints()) { out.println(endpoint.getComponent().getURI() + "/" + endpoint.getService().getName()); for (Binding b : endpoint.getService().getBindings()) { if (!SCABinding.TYPE.equals(b.getType())) { out.println(" " + b.getType().getLocalPart() + " " + b.getURI()); } } } return true; }
/** * Follow a service promotion chain down to the innermost (non-composite) component. * * @param compositeService * @return */ public Component getPromotedComponent(CompositeService compositeService) { ComponentService componentService = compositeService.getPromotedService(); if (componentService != null) { Service service = componentService.getService(); if (componentService.getName() != null && service instanceof CompositeService) { // Continue to follow the service promotion chain return getPromotedComponent((CompositeService)service); } else { // Found a non-composite service return compositeService.getPromotedComponent(); } } else { // No promoted service return null; } }
/** * Init the comet binding server-side infrastructure. */ @Override public void start() { String deployedURI = ServletFactory.registerServlet(this.servletHost); endpoint.setDeployedURI(deployedURI); final ComponentService service = this.endpoint.getService(); final Interface serviceInterface = service.getInterfaceContract().getInterface(); JavascriptGenerator.generateServiceProxy(service); for (final Operation operation : serviceInterface.getOperations()) { final String url = "/" + endpoint.getService().getName() + "/" + operation.getName(); CometEndpointManager.add(url, endpoint); CometOperationManager.add(url, operation); JavascriptGenerator.generateMethodProxy(service, operation); } }