public void visitMethod(Context annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { Type type = helper.getGenericType(method); MethodInjectionSite site = new MethodInjectionSite(method, 0); visit(type, componentType, site, method.getDeclaringClass(), method, context); }
public Class<?> getMemberType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type: " + site.getClass()); } }
try { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getSignature().getMethod(implementationClass); return method.getGenericParameterTypes()[methodSite.getParam()]; } catch (ClassNotFoundException e) { throw new AssertionError(e);
/** * Obtain the fields and methods for injection sites associated with the instance * * @param mappings the mappings of injection sites */ private void initializeInjectionSites(Map<InjectionSite, Injectable> mappings) { this.sites = new HashMap<>(); for (Map.Entry<InjectionSite, Injectable> entry : mappings.entrySet()) { InjectionSite site = entry.getKey(); if (site instanceof FieldInjectionSite) { try { Field field = getField(((FieldInjectionSite) site).getName()); sites.put(field, entry.getValue()); } catch (NoSuchFieldException e) { // programming error throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodInjectionSite = (MethodInjectionSite) site; Method method = methodInjectionSite.getMethod(); sites.put(method, entry.getValue()); } else { // ignore other injection sites } } }
private Method getMethod(MethodInjectionSite methodSite, String implementationClass, ClassLoader classLoader) throws ClassNotFoundException, NoSuchMethodException { Class<?> clazz = classLoader.loadClass(implementationClass); return methodSite.getSignature().getMethod(clazz); }
injector = reflectionFactory.createInjector(((FieldInjectionSite) site).getField(), supplier); } else if (site instanceof MethodInjectionSite) { injector = reflectionFactory.createInjector(((MethodInjectionSite) site).getMethod(), supplier); } else { throw new UnsupportedOperationException("Unsupported injection site type: " + site.getClass());
try { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getSignature().getMethod(implementationClass); Injector<?> injector = reflectionFactory.createInjector(method, factory); injectors.put(attribute, injector);
public void visitMethod(Channel annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { MethodInjectionSite site = new MethodInjectionSite(method, 0); String name = helper.getSiteName(method, null); Class<?> type = method.getParameterTypes()[0]; createReference(name, annotation, type, componentType, site, implClass, context); }
public Class<?> getMemberType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type: " + site.getClass()); } }
Method method = methodSite.getMethod(); Injector<?> injector = reflectionFactory.createInjector(method, supplier); injectors.put(attribute, injector);
Method method = methodSite.getSignature().getMethod(implementationClass); return method.getParameterTypes()[methodSite.getParam()]; } catch (ClassNotFoundException e) { throw new AssertionError(e);
public void visitMethod(Context annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { Type type = helper.getGenericType(method); MethodInjectionSite site = new MethodInjectionSite(method, 0); visit(type, componentType, site, method.getDeclaringClass(), method, context); }
public Type getGenericType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getGenericType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type " + site.getClass()); } }
Method method = methodSite.getMethod(); Injector<?> injector = reflectionFactory.createInjector(method, supplier); injectors.put(attribute, injector);
public void visitMethod(Channel annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { MethodInjectionSite site = new MethodInjectionSite(method, 0); String name = helper.getSiteName(method, null); Class<?> type = method.getParameterTypes()[0]; createReference(name, annotation, type, componentType, site, implClass, context); }
public Type getGenericType(Injectable injectable) { InjectionSite site = findInjectionSite(injectable); if (site == null) { throw new AssertionError("No injection site for " + injectable + " in " + implementationClass); } if (site instanceof FieldInjectionSite) { try { FieldInjectionSite fieldSite = (FieldInjectionSite) site; Field field = getField(fieldSite.getName()); return field.getGenericType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } } else if (site instanceof MethodInjectionSite) { MethodInjectionSite methodSite = (MethodInjectionSite) site; Method method = methodSite.getMethod(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else if (site instanceof ConstructorInjectionSite) { ConstructorInjectionSite methodSite = (ConstructorInjectionSite) site; Constructor<?> method = methodSite.getConstructor(); return method.getGenericParameterTypes()[methodSite.getParam()]; } else { throw new AssertionError("Invalid injection site type " + site.getClass()); } }
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)); } }
public void visitMethod(PersistenceUnit annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { MethodInjectionSite site = new MethodInjectionSite(method, 0); PersistenceUnitResourceReference definition = createDefinition(annotation); componentType.add(definition, site); }
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)); } }
public void visitMethod(PersistenceUnit annotation, Method method, Class<?> implClass, InjectingComponentType componentType, IntrospectionContext context) { MethodInjectionSite site = new MethodInjectionSite(method, 0); PersistenceUnitResourceReference definition = createDefinition(annotation); componentType.add(definition, site); }