org.osgl.inject.Genie Java Examples
The following examples show how to use
org.osgl.inject.Genie.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GH55.java From java-di with Apache License 2.0 | 6 votes |
@Test public void test() { Genie genie = Genie.create(new Module() { @Override protected void configure() { bind(TypedElementLoader.class).to(new TypedElementLoader() { @Override protected List<Class> load(Class type, boolean loadNonPublic, boolean loadAbstract, boolean loadRoot) { List<Class> list = new ArrayList<>(); list.add(Size.class); return list; } }); } }); GH55 gh55 = genie.get(GH55.class); eq(3, gh55.sizes.size()); }
Example #2
Source File: GH56.java From java-di with Apache License 2.0 | 6 votes |
@Test public void test() { Genie genie = Genie.create(new Module() { @Override protected void configure() { bind(TypedElementLoader.class).to(new TypedElementLoader() { @Override protected List<Class> load(Class type, boolean loadNonPublic, boolean loadAbstract, boolean loadRoot) { List<Class> list = new ArrayList<>(); list.add(Color.class); return list; } }); } }); GH56 gh56 = genie.get(GH56.class); eq(3, gh56.colorList.size()); eq(Color.B, gh56.colorLookup.get("B")); }
Example #3
Source File: GH54.java From java-di with Apache License 2.0 | 6 votes |
@Test public void test() { Genie genie = Genie.create(new Module() { @Override protected void configure() { bind(TypedElementLoader.class).to(new TypedElementLoader() { @Override protected List<Class> load(Class type, boolean loadNonPublic, boolean loadAbstract, boolean loadRoot) { List<Class> list = new ArrayList<>(); list.add(Color.class); return list; } }); } }); GH54 gh54 = genie.get(GH54.class); eq(Color.DarkBlue, gh54.colors.get(Keyword.of("dark-blue"))); }
Example #4
Source File: GH34.java From java-di with Apache License 2.0 | 6 votes |
@Test public void test() { Genie genie = Genie.create(); genie.registerGenericTypedBeanLoader(BaseMapper.class, new GenericTypedBeanLoader<BaseMapper>() { @Override public BaseMapper load(BeanSpec spec) { List<Type> typeParams = spec.typeParams(); if (typeParams.size() > 0) { Type type = typeParams.get(0); if (type.equals(PackItem.class)) { return new ItemMapper(); } } return null; } }); ItemService itemService = genie.get(ItemService.class); notNull(itemService); notNull(itemService.mapper); }
Example #5
Source File: TypedElementLoader.java From java-di with Apache License 2.0 | 5 votes |
/** * This method will load instances of all public and non-abstract classes that * implements/extends the interface/class specified as `value` option * * @param options must contains an entry indexed with "value" and the value should be a Class type * @param container the bean spec of the container into which the element will be loaded * @param genie the dependency injector * @return the list of bean instances whose class is sub class or implementation of `hint` */ @Override public final Iterable<T> load(Map<String, Object> options, BeanSpec container, final Genie genie) { ElementType elementType = (ElementType)options.get("elementType"); boolean loadNonPublic = (Boolean)options.get("loadNonPublic"); boolean loadRoot = (Boolean) options.get("loadRoot"); $.Var<ElementType> typeVar = $.var(elementType); Class<T> targetClass = targetClass(typeVar, options, container); boolean loadAbstract = typeVar.get().loadAbstract() && (Boolean) options.get("loadAbstract"); List<Class<? extends T>> classes = load(targetClass, loadNonPublic, loadAbstract, loadRoot); return (Iterable<T>)typeVar.get().transform((List)classes, genie); }
Example #6
Source File: GH47.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); BeanSpec spec = BeanSpec.of(Foo.class, genie); List<BeanSpec> fields = spec.nonStaticFields(); spec = fields.get(0); fields = spec.nonStaticFields(); eq(9, fields.size()); }
Example #7
Source File: GH45.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); Field field = $.fieldOf(Foo.class, "list"); Type type = field.getGenericType(); Map<String, Class> typeLookup = C.Map("ID", Long.class); BeanSpec spec = BeanSpec.of(type, genie, typeLookup); List<Type> typeParams = spec.typeParams(); eq(Long.class, typeParams.get(0)); }
Example #8
Source File: GH57.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); BeanSpec spec = BeanSpec.of(TestResp.class, genie); Map<String, BeanSpec> fieldSpecs = spec.fields(); eq(Object.class, fieldSpecs.get("result").rawType()); eq(Integer.class, fieldSpecs.get("code").rawType()); }
Example #9
Source File: GH38.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); LinkedHashMap<String, Integer> map = genie.get(LinkedHashMap.class); notNull(map); yes(map.isEmpty()); }
Example #10
Source File: GH25.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); genie.registerNamedProvider(Foo.class, new FooProvider()); FooHolder fooHolder = genie.get(FooHolder.class); eq("bar", fooHolder.foo.name); }
Example #11
Source File: Gh19.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); BeanSpec spec = BeanSpec.of(IntA.class, genie); yes(spec.isInterface()); spec = BeanSpec.of(Gh19.class, genie); no(spec.isInterface()); }
Example #12
Source File: GH26.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); BeanSpec fooHolderSpec = BeanSpec.of(FooHolder.class, genie); BeanSpec fooSpec = fooHolderSpec.field("foo"); BeanSpec dataSpec = fooSpec.field("data"); eq(String.class, dataSpec.rawType()); }
Example #13
Source File: GH51.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); BeanSpec spec = BeanSpec.of(Me.class, genie); BeanSpec t = spec.field("t"); BeanSpec id = t.field("id"); eq(Integer.class, id.rawType()); }
Example #14
Source File: GH33.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); BeanSpec spec = BeanSpec.of(ItemMapper.class, genie); BeanSpec parent = spec.parent(); List<Type> typeParams = parent.typeParams(); eq(1, typeParams.size()); eq(PackItem.class, typeParams.get(0)); }
Example #15
Source File: GH46.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); BeanSpec spec = BeanSpec.of(char.class, genie); isNull(spec.parent()); isEmpty(spec.fields()); }
Example #16
Source File: GH43.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); Method method = $.getMethod(Foo.class, "doIt", List.class); Map<String, Class> typeVarLookup = Generics.buildTypeParamImplLookup(IntFoo.class); Type type = method.getGenericParameterTypes()[0]; Annotation[] anno = method.getParameterAnnotations()[0]; BeanSpec spec = BeanSpec.of(type, anno, genie, typeVarLookup); }
Example #17
Source File: AnnotatedElementLoader.java From java-di with Apache License 2.0 | 5 votes |
/** * This method will load instances of all public and non-abstract classes that * has been annotated by annotation class specified as `value` in `options` * * @param options optional parameters specified to refine the loading process * @param container the bean spec about the container into which the bean to be loaded * @param genie the dependency injector * @return the list of bean instances */ @Override public Iterable<Object> load(Map<String, Object> options, BeanSpec container, final Genie genie) { Object hint = options.get("value"); E.illegalArgumentIf(!Annotation.class.isAssignableFrom((Class) hint)); boolean loadNonPublic = (Boolean)options.get("loadNonPublic"); ElementType elementType = elementType(options, container); boolean loadAbstract = elementType.loadAbstract() && (Boolean) options.get("loadAbstract"); List<Class<?>> classes = load(annoClassFromHint(hint), loadNonPublic, loadAbstract); return elementType.transform(classes, genie); }
Example #18
Source File: Gh58.java From java-di with Apache License 2.0 | 5 votes |
@Test public void test() { Genie genie = Genie.create(); Integer i = genie.get(Integer.class); BeanSpec fooSpec = BeanSpec.of(Foo.class, genie); no(genie.subjectToInject(fooSpec)); genie.get(Foo.class); no(genie.subjectToInject(fooSpec)); }
Example #19
Source File: GH21.java From java-di with Apache License 2.0 | 5 votes |
@Test public void testEquality() { Genie genie = Genie.create(); Field xfoo = $.fieldOf(X.class, "foo"); Field yfoo = $.fieldOf(Y.class, "foo"); assertNotEquals(BeanSpec.of(xfoo, genie), BeanSpec.of(yfoo, genie)); }
Example #20
Source File: Gh18.java From java-di with Apache License 2.0 | 5 votes |
@Test @Ignore public void test() { Genie genie = Genie.create(); BeanSpec spec = BeanSpec.of(int[].class, genie); eq(int.class, spec.typeParams().get(0)); }
Example #21
Source File: ArrayProvider.java From java-di with Apache License 2.0 | 5 votes |
public static ArrayProvider of(BeanSpec beanSpec, Genie genie) { if (!beanSpec.isArray()) { throw new IllegalArgumentException("Array bean spec required"); } Class arrayClass = beanSpec.rawType(); return new ArrayProvider(arrayClass.getComponentType(), beanSpec.toList(), genie); }
Example #22
Source File: GH181.java From java-tool with Apache License 2.0 | 4 votes |
@Test public void test() { Genie genie = Genie.create(); Order.Dao orderDao = genie.get(Order.Dao.class); notNull(orderDao.accDao); }
Example #23
Source File: Act.java From actframework with Apache License 2.0 | 4 votes |
private static Genie genie() { if (null == genie) { genie = Genie.create(); } return genie; }
Example #24
Source File: ArrayProvider.java From java-di with Apache License 2.0 | 4 votes |
private ArrayProvider(Class elementType, Genie genie) { this.elementType = elementType; this.listSpec = BeanSpec.of(ArrayList.class, null, genie); this.genie = genie; }
Example #25
Source File: ArrayProvider.java From java-di with Apache License 2.0 | 4 votes |
private ArrayProvider(Class elementType, BeanSpec listSpec, Genie genie) { this.elementType = elementType; this.listSpec = listSpec; this.genie = genie; }
Example #26
Source File: ArrayProvider.java From java-di with Apache License 2.0 | 4 votes |
public static ArrayProvider of(Class arrayClass, Genie genie) { if (!arrayClass.isArray()) { throw new IllegalArgumentException("Array class expected"); } return new ArrayProvider(arrayClass.getComponentType(), genie); }
Example #27
Source File: Gh59.java From java-di with Apache License 2.0 | 4 votes |
@Test public void test() { Genie genie = Genie.create(); eq(0, genie.get(Integer.class)); }
Example #28
Source File: GH42.java From java-di with Apache License 2.0 | 4 votes |
@Test public void test() { Genie genie = Genie.create(); Order.Dao orderDao = genie.get(Order.Dao.class); notNull(orderDao.accDao); }
Example #29
Source File: GH10.java From java-di with Apache License 2.0 | 4 votes |
@Test public void test() { Genie genie = Genie.create(Binder.class); A a = genie.get(A.class); eq("foo", a.a()); }
Example #30
Source File: GH50.java From java-di with Apache License 2.0 | 4 votes |
@Test public void test() { Genie genie = Genie.create(); genie.get(Me.class); }