private void configureGhost(BeanManager bm, BeanConfigurator<Ghost> ghost) { // creation using read from bean attributes ghost.read(bm.createBeanAttributes(bm.createAnnotatedType(Ghost.class))); ghost.beanClass(Ghost.class); ghost.addQualifier(Undead.UndeadLiteral.INSTANCE); ghost.addStereotype(Monster.class); ghost.scope(RequestScoped.class); // test replacement of IPs InjectionPoint ghostWeaponIP = null; InjectionPoint ghostDesireIP = null; for (AnnotatedField<? super Ghost> field : bm.createAnnotatedType(Ghost.class).getFields()) { if (field.getJavaMember().getType().equals(DesireToHurtHumans.class)) { ghostDesireIP = bm.createInjectionPoint(field); } if (field.getJavaMember().getType().equals(Weapon.class)) { ghostWeaponIP = bm.createInjectionPoint(field); } } // firstly add one IP, then replace it with other ghost.addInjectionPoint(ghostWeaponIP); ghost.injectionPoints(ghostDesireIP); // set producing ghost.produceWith(MonsterController.getGhostInstance); }
private void configureZombie(BeanManager bm, BeanConfigurator<Zombie> zombie) { // init with read() method, then set values zombie.read(bm.createAnnotatedType(Zombie.class)); zombie.beanClass(Zombie.class); zombie.addQualifiers(Undead.UndeadLiteral.INSTANCE, Dangerous.DangerousLiteral.INSTANCE); zombie.addStereotype(Monster.class); zombie.scope(RequestScoped.class); InjectionPoint zombieWeaponIP = null; InjectionPoint zombieDesireIP = null; for (AnnotatedField<? super Zombie> field : bm.createAnnotatedType(Zombie.class).getFields()) { if (field.getJavaMember().getType().equals(DesireToHurtHumans.class)) { zombieDesireIP = bm.createInjectionPoint(field); } if (field.getJavaMember().getType().equals(Weapon.class)) { zombieWeaponIP = bm.createInjectionPoint(field); } } // add multiple injection points zombie.addInjectionPoints(zombieWeaponIP, zombieDesireIP); // set Function as a supplier zombie.produceWith(MonsterController.zombieProducingFunction); // set BiConsumer to destroyWith zombie.destroyWith(MonsterController.zombieConsumer); // make passivation capable zombie.id("zombie"); }
private void configureVampire(BeanManager bm, BeanConfigurator<Vampire> vampire) { vampire.read(bm.createAnnotatedType(Vampire.class)); vampire.beanClass(Vampire.class); vampire.addQualifier(Undead.UndeadLiteral.INSTANCE); vampire.addStereotype(Monster.class); vampire.scope(RequestScoped.class); // set createWith function vampire.createWith((CreationalContext<Vampire> creationalContext) -> { MonsterController.vampireInstanceCreated = true; AnnotatedType<Vampire> at = bm.createAnnotatedType(Vampire.class); BeanAttributes<Vampire> ba = bm.createBeanAttributes(at); return bm.createBean(ba, Vampire.class, bm.getInjectionTargetFactory(at)).create(creationalContext); }); }