@Override public Object get() { try { return constructor.newInstance(params(pp)); } catch (Exception e) { throw new InjectException(e, "cannot instantiate %s", spec); } } };
@Override public Object get() { try { return constructor.newInstance(params(pp)); } catch (Exception e) { throw new InjectException(e, "cannot instantiate %s", spec); } } };
Object applyTo(Object bean) { try { return method.invoke(bean, params(providers)); } catch (Exception e) { throw new InjectException(e, "Unable to invoke method[%s] on %s", method.getName(), bean.getClass()); } }
Object applyTo(Object bean) { try { return method.invoke(bean, params(providers)); } catch (Exception e) { throw new InjectException(e, "Unable to invoke method[%s] on %s", method.getName(), bean.getClass()); } }
Constructor getDeclaredConstructor() { try { return rawType().getDeclaredConstructor(); } catch (NoSuchMethodException e) { throw new InjectException(e, "cannot instantiate %s", rawType); } }
void setField(Object bean, Object value) { E.illegalStateIf(null == field); try { field.set(bean, value); } catch (Exception e) { throw new InjectException(e, "Unable to inject field value on %s", bean.getClass()); } }
Constructor getDeclaredConstructor() { try { return rawType().getDeclaredConstructor(); } catch (NoSuchMethodException e) { throw new InjectException(e, "cannot instantiate %s", rawType); } }
void setField(Object bean, Object value) { E.illegalStateIf(null == field); try { field.set(bean, value); } catch (Exception e) { throw new InjectException(e, "Unable to inject field value on %s", bean.getClass()); } }
/** * Add qualifier annotation constraints to this binder * * Each qualifier annotation type must be tagged with {@link Qualifier} annotation. * Otherwise an {@link InjectException} will be thrown out * * @param qualifiers * an array of qualifier annotation types * @return this binder instance * @throws InjectException * if the any qualifier class is not tagged with {@link Qualifier} * @see Qualifier */ public Binder<T> qualifiedWith(Class<? extends Annotation>... qualifiers) { for (Class<? extends Annotation> qualifier : qualifiers) { if (!qualifier.isAnnotationPresent(Qualifier.class)) { throw new InjectException( "Qualifier annotation type must have \"@Qualifier\" annotation presented: " + qualifier.getName()); } this.annotations.add(AnnotationUtil.createAnnotation(qualifier)); } this.fireEvent = false; return this; }
/** * Add qualifier annotation constraints to this binder * * Each qualifier annotation type must be tagged with {@link Qualifier} annotation. * Otherwise an {@link InjectException} will be thrown out * * @param qualifiers * an array of qualifier annotation types * @return this binder instance * @throws InjectException * if the any qualifier class is not tagged with {@link Qualifier} * @see Qualifier */ public Binder<T> qualifiedWith(Class<? extends Annotation>... qualifiers) { for (Class<? extends Annotation> qualifier : qualifiers) { if (!qualifier.isAnnotationPresent(Qualifier.class)) { throw new InjectException( "Qualifier annotation type must have \"@Qualifier\" annotation presented: " + qualifier.getName()); } this.annotations.add(AnnotationUtil.createAnnotation(qualifier)); } this.fireEvent = false; return this; }
private Class<T> targetClass($.Var<ElementType> typeVar, Map<String, Object> options, BeanSpec container) { Object hint = options.get("value"); E.illegalArgumentIf(!(hint instanceof Class)); Class<?> targetClass = $.cast(hint); Class<?> inferredTargetClass = LoaderUtil.targetClass(typeVar, container); if (null != inferredTargetClass) { if (TypeOf.PlaceHolder.class == targetClass) { targetClass = inferredTargetClass; } else if (!inferredTargetClass.isAssignableFrom(targetClass)) { throw new InjectException("specified class[%s] doesn't match the container spec: %s", targetClass, container); } } else if (TypeOf.PlaceHolder.class == targetClass) { if (TypeOf.PlaceHolder.class == targetClass) { throw new InjectException("Cannot load element - target type info is missing"); } } return $.cast(targetClass); }
private Class<T> targetClass($.Var<ElementType> typeVar, Map<String, Object> options, BeanSpec container) { Object hint = options.get("value"); E.illegalArgumentIf(!(hint instanceof Class)); Class<?> targetClass = $.cast(hint); Class<?> inferredTargetClass = LoaderUtil.targetClass(typeVar, container); if (null != inferredTargetClass) { if (TypeOf.PlaceHolder.class == targetClass) { targetClass = inferredTargetClass; } else if (!inferredTargetClass.isAssignableFrom(targetClass)) { throw new InjectException("specified class[%s] doesn't match the container spec: %s", targetClass, container); } } else if (TypeOf.PlaceHolder.class == targetClass) { if (TypeOf.PlaceHolder.class == targetClass) { throw new InjectException("Cannot load element - target type info is missing"); } } return $.cast(targetClass); }
private T cast(Object val, BeanSpec spec) { Class<?> type = spec.rawType(); if (type.isInstance(val)) { return (T) val; } if ($.isSimpleType(type)) { StringValueResolver svr = StringValueResolver.predefined(type); if (null != svr) { return (T) svr.resolve(S.string(val)); } } throw new InjectException("Cannot cast value type[%s] to required type[%]", val.getClass(), type); } }
private T cast(Object val, BeanSpec spec) { Class<?> type = spec.rawType(); if (type.isInstance(val)) { return (T) val; } if ($.isSimpleType(type)) { StringValueResolver svr = StringValueResolver.predefined(type); if (null != svr) { return (T) svr.resolve(S.string(val)); } } throw new InjectException("Cannot cast value type[%s] to required type[%]", val.getClass(), type); } }
/** * Register this binder to `Genie` * * @param genie * the dependency injector */ public void register(Genie genie) { if (null == provider) { if (null != constructor) { provider = genie.buildConstructor( constructor, BeanSpec.of(constructor.getDeclaringClass(), null, genie), new HashSet<BeanSpec>()); } else if (null != impl) { provider = new LazyProvider<>(impl, genie); } } if (!bound()) { throw new InjectException("Cannot register without binding specified"); } BeanSpec spec = beanSpec(genie); genie.addIntoRegistry(spec, genie.decorate(spec, provider, true), annotations.isEmpty() && S.blank(name)); if (fireEvent || forceFireEvent) { genie.fireProviderRegisteredEvent(type); } }
@Override public T get() { String confKey = value(); if (S.isBlank(confKey)) { throw new InjectException(("Missing configuration key")); } Object conf = conf(confKey, defaultValue); if (null == conf) { return null; } return cast(conf, spec); }
/** * Register this binder to `Genie` * * @param genie * the dependency injector */ public void register(Genie genie) { if (null == provider) { if (null != constructor) { provider = genie.buildConstructor( constructor, BeanSpec.of(constructor.getDeclaringClass(), null, genie), new HashSet<BeanSpec>()); } else if (null != impl) { provider = new LazyProvider<>(impl, genie); } } if (!bound()) { throw new InjectException("Cannot register without binding specified"); } BeanSpec spec = beanSpec(genie); genie.addIntoRegistry(spec, genie.decorate(spec, provider, true), annotations.isEmpty() && S.blank(name)); if (fireEvent || forceFireEvent) { genie.fireProviderRegisteredEvent(type); } }
@Override public T get() { String confKey = value(); if (S.isBlank(confKey)) { throw new InjectException(("Missing configuration key")); } Object conf = conf(confKey, defaultValue); if (null == conf) { return null; } return cast(conf, spec); }
private void resolveScope(Annotation annotation, Injector injector) { if (stopInheritedScope) { return; } Class<? extends Annotation> annoClass = annotation.annotationType(); if (injector.isInheritedScopeStopper(annoClass)) { stopInheritedScope = true; scope = null; } else if (injector.isScope(annoClass)) { if (null != scope) { Class<? extends Annotation> newScope = injector.scopeByAlias(annoClass); if (newScope != scope) { throw new InjectException("Incompatible scope annotation found: %s", this); } } else { scope = injector.scopeByAlias(annoClass); // scope annotaton is a decorator for inject library usage, it // can't add scope annotation into annoData and make it // enter the equals and hashCode calculation, //annoData.add(new AnnoData(annotation)); } } }
private void resolveScope(Annotation annotation, Injector injector) { if (stopInheritedScope) { return; } Class<? extends Annotation> annoClass = annotation.annotationType(); if (injector.isInheritedScopeStopper(annoClass)) { stopInheritedScope = true; scope = null; } else if (injector.isScope(annoClass)) { if (null != scope) { Class<? extends Annotation> newScope = injector.scopeByAlias(annoClass); if (newScope != scope) { throw new InjectException("Incompatible scope annotation found: %s", this); } } else { scope = injector.scopeByAlias(annoClass); // scope annotaton is a decorator for inject library usage, it // can't add scope annotation into annoData and make it // enter the equals and hashCode calculation, //annoData.add(new AnnoData(annotation)); } } }