@Override public BindingBuilder<T> to(Class<? super T> type) { Objects.requireNonNull(type); _key = Key.of(type); return this; }
BindingBuilderImpl(InjectorBuilder builder, Class<T> type) { Objects.requireNonNull(builder); _builder = builder; Objects.requireNonNull(type); _key = Key.of(type); _impl = type; }
static <T> InjectionPoint<T> of(Field f) { return new InjectionPointImpl<>(Key.of(f), f.getGenericType(), f.getName(), f.getAnnotations(), f.getDeclaringClass()); }
/** * Creates a new instance for a given type. */ @Override public <T> T instance(Class<T> type) { Key<T> key = Key.of(type); return instance(key); }
static <T> InjectionPoint<T> of(Class<T> type) { return new InjectionPointImpl<>(Key.of(type), type, type.getSimpleName(), type.getAnnotations(), type); }
static <T> InjectionPoint<T> of(Method m) { return new InjectionPointImpl<>(Key.of(m), m.getGenericReturnType(), m.getName(), m.getAnnotations(), m.getDeclaringClass()); }
InjectField(InjectorAmp inject, Field field) { _inject = inject; _field = field; _field.setAccessible(true); _isOptional = field.isAnnotationPresent(Opt.class); _key = Key.of(field); _program = _inject.provider(this); }
static <T> InjectionPoint<T> of(Class<?> declaringClass, Class<T> paramType, Annotation []annotations) { return new InjectionPointImpl<>(Key.of(paramType), paramType, declaringClass.getName(), annotations, declaringClass); }
@Override public ConvertManager converter() { if (_convertManager == null) { _convertManager = provider(Key.of(ConvertManager.class)); } return _convertManager.get(); }
@Override public <T> ServiceBuilder service(Class<T> type) { Key<?> key = Key.of(type, ServiceImpl.class); return service(key, type); }
static <T> InjectionPoint<T> of(Constructor<?> c) { return new InjectionPointImpl<>(Key.of(c), c.getDeclaringClass(), c.getDeclaringClass().getSimpleName(), c.getAnnotations(), c.getDeclaringClass()); }
/** * Returns an object producer. */ private <T> BindingAmp<T> findObjectBinding(Key<T> key) { Objects.requireNonNull(key); if (key.qualifiers().length != 1) { throw new IllegalArgumentException(); } return (BindingAmp) findBinding(Key.of(Object.class, key.qualifiers()[0])); }
@Override public <T> ServiceRef.ServiceBuilder service(Class<T> serviceClass) { Objects.requireNonNull(serviceClass); validator().serviceClass(serviceClass); Key<?> key = Key.of(serviceClass, ServiceImpl.class); ServiceBuilderWebImpl service = new ServiceBuilderWebImpl(this, key, serviceClass); _includes.add(service); return service; }
BindingBuilderImpl(InjectorBuilder builder, Function<?,T> function) { Objects.requireNonNull(builder); _builder = builder; Objects.requireNonNull(function); Class<T> keyType = (Class) TypeRef.of(function.getClass()) .to(Function.class) .param(1) .rawClass(); _key = (Key) Key.of(keyType); _function = function; }
static <T> InjectionPoint<T> of(Parameter p) { return new InjectionPointImpl<>((Key<T>) Key.of(p), p.getParameterizedType(), p.getName(), p.getAnnotations(), p.getDeclaringExecutable().getDeclaringClass()); }
public ServerAuthManager() { _security = SecuritySystem.getCurrent(); InjectorAmp injectManager = InjectorAmp.current(); _auth = injectManager.instance(io.baratine.inject.Key.of(AuthenticatorRole.class, Admin.class)); if (_auth == null) { _auth = injectManager.instance(AuthenticatorRole.class); } }
void bind(InjectorImpl injector) { addBean(injector, Key.of(Injector.class), ()->injector); for (IncludeBuilder include : includes()) { include.build(injector); } for (BindingBuilderImpl<?> binding : _bindings) { binding.build(injector); } }
private void introspectOnLookup() { if (isImplemented(OnLookup.class)) { return; } Key<T> key = Key.of(_type, ServiceImpl.class); // XXX: provider should be passed in? Non-injector session provider? Provider<T> provider = services().injector().provider(key); FieldBean<T> setter = findIdSetter(); MethodAmp onLookup = new MethodOnLookup(_stubClassSession, provider, setter); onLookup(onLookup); }
@Override public <T> WebBuilder view(Class<? extends ViewRender<T>> viewClass) { TypeRef viewType = TypeRef.of(viewClass).to(ViewRender.class); TypeRef typeRef = viewType.param(0); Class renderedType = Object.class; if (typeRef != null) renderedType = typeRef.rawClass(); ViewRender<?> view = injector().instance(viewClass); return view(view, Key.of(renderedType)); }
private void introspectOnLookup() { if (isImplemented(OnLookup.class)) { return; } Class<?> entityClass = _configResource.entityType(); Key<Object> key = (Key) Key.of(entityClass); Provider<Object> provider = services().injector().provider(key); MethodHandle setter = findIdSetter(); Convert<String,?> converter = findConverter(); MethodAmp onLookup = new MethodOnLookup(_stubAsset, provider, converter, setter); onLookup(onLookup); }