/** * Constructor. * * @param uri the reference URI * @param definition the reference type definition * @param parent the parent component */ public LogicalReference(URI uri, Reference<ComponentType> definition, LogicalComponent<?> parent) { super(uri, definition != null ? definition.getServiceContract() : null, parent); this.definition = definition; }
private void generateReferenceInjectionMapping(Reference<ComponentType> definition, WebComponentType type, Map<String, Map<String, InjectionSite>> mappings) { Map<String, InjectionSite> mapping = mappings.get(definition.getName()); if (mapping == null) { mapping = new HashMap<>(); mappings.put(definition.getName(), mapping); } for (Map.Entry<String, Map<InjectionSite, Injectable>> entry : type.getInjectionSites().entrySet()) { for (Map.Entry<InjectionSite, Injectable> siteMap : entry.getValue().entrySet()) { if (siteMap.getValue().getName().equals(definition.getName())) { mapping.put(entry.getKey(), siteMap.getKey()); } } } ServiceContract contract = definition.getServiceContract(); Class<?> interfaceClass = contract.getInterfaceClass(); // inject the reference into the session context WebContextInjectionSite site = new WebContextInjectionSite(interfaceClass, SESSION_CONTEXT); mapping.put(SESSION_CONTEXT_SITE, site); // also inject the reference into the servlet context WebContextInjectionSite servletContextSite = new WebContextInjectionSite(interfaceClass, SERVLET_CONTEXT); mapping.put(SERVLET_CONTEXT_SITE, servletContextSite); }
private void handleReference(Reference<?> reference, InjectionSite site, Class<?> implClass, Map<AccessibleObject, Supplier<Object>> injectors) { if (reference.getBindings().isEmpty()) { return; } Class<?> interfaze = reference.getServiceContract().getInterfaceClass(); Binding binding = reference.getBindings().get(0); AccessibleObject accessibleObject; if (site instanceof FieldInjectionSite) { accessibleObject = ((FieldInjectionSite) site).getField(); } else if (site instanceof MethodInjectionSite) { accessibleObject = ((MethodInjectionSite) site).getMethod(); } else { // ignore return; } // create supplier to resolve the proxy injectors.put(accessibleObject, () -> serviceResolver.resolve(interfaze, binding, implClass)); } }
private void handleReference(Reference<?> reference, InjectionSite site, Class<?> implClass, Map<AccessibleObject, Supplier<Object>> injectors) { if (reference.getBindings().isEmpty()) { return; } Class<?> interfaze = reference.getServiceContract().getInterfaceClass(); Binding binding = reference.getBindings().get(0); AccessibleObject accessibleObject; if (site instanceof FieldInjectionSite) { accessibleObject = ((FieldInjectionSite) site).getField(); } else if (site instanceof MethodInjectionSite) { accessibleObject = ((MethodInjectionSite) site).getMethod(); } else { // ignore return; } // create supplier to resolve the proxy injectors.put(accessibleObject, () -> serviceResolver.resolve(interfaze, binding, implClass)); } }
ServiceContract contract = reference.getServiceContract(); if (contract.getCallbackContract() != null) { Binding callbackBinding = processReferenceCallback(castAnnotation, reference, implClass, context);
Reference<ComponentType> reference = componentType.getReferences().get(name); if (reference != null) { ServiceContract source = reference.getServiceContract(); ServiceContract target = entry.getValue().getServiceContract(); MatchResult result = matcher.isAssignableFrom(source, target, false); if (!result.isAssignable()) {
protected void processBindingAnnotations(AccessibleObject object, Reference reference, Class<?> implClass, IntrospectionContext context) { A annotations[] = object.getAnnotationsByType(annotationType); if (annotations.length == 0) { // check meta-annotations for (Annotation annotation : object.getAnnotations()) { annotations = annotation.annotationType().getAnnotationsByType(annotationType); if (annotations.length > 0) { break; } } if (annotations.length == 0) { return; } } for (A annotation : annotations) { Binding binding = processReference(annotation, reference, implClass, context); if (binding == null) { continue; } reference.addBinding(binding); ServiceContract contract = reference.getServiceContract(); if (contract.getCallbackContract() != null) { Binding callbackBinding = processReferenceCallback(annotationType.cast(annotation), reference, implClass, context); if (callbackBinding != null) { reference.addCallbackBinding(callbackBinding); } } } }
public void generateWireSource(JavaWireSource source, LogicalReference reference) { URI uri = reference.getUri(); JavaServiceContract serviceContract = (JavaServiceContract) reference.getDefinition().getServiceContract(); source.setUri(uri); source.setInjectable(new Injectable(InjectableType.REFERENCE, uri.getFragment())); source.setInterfaceClass(serviceContract.getInterfaceClass()); // assume for now that any wire from a Java component can be optimized source.setOptimizable(true); if (reference.getDefinition().isKeyed()) { source.setKeyed(true); DataType type = reference.getDefinition().getKeyDataType(); String className = type.getType().getName(); source.setKeyClassName(className); } }
public PhysicalWireSource generateSource(LogicalReference reference) throws Fabric3Exception { URI uri = reference.getUri(); SystemWireSource definition = new SystemWireSource(); definition.setOptimizable(true); definition.setUri(uri); definition.setInjectable(new Injectable(InjectableType.REFERENCE, uri.getFragment())); JavaServiceContract serviceContract = (JavaServiceContract) reference.getDefinition().getServiceContract(); definition.setInterfaceClass(serviceContract.getInterfaceClass()); if (reference.getDefinition().isKeyed()) { definition.setKeyed(true); String className = reference.getDefinition().getKeyDataType().getType().getName(); definition.setKeyClassName(className); } return definition; }