public void removeSupplier(Injectable injectable) { for (Iterator<Map.Entry<Supplier, Injectable>> iterator = reinjectionMappings.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<Supplier, Injectable> entry = iterator.next(); if (injectable.equals(entry.getValue())) { iterator.remove(); break; } } }
public void endUpdate() { for (Map.Entry<Injectable, Supplier<?>> entry : factories.entrySet()) { // signal to multiplicity factories updates are complete Injectable injectable = entry.getKey(); Supplier<?> factory = entry.getValue(); if (InjectableType.REFERENCE == injectable.getType() || InjectableType.CALLBACK == injectable.getType()) { if (factory instanceof MultiplicitySupplier) { MultiplicitySupplier<?> multiplicitySupplier = (MultiplicitySupplier<?>) factory; multiplicitySupplier.endUpdate(); } } } }
public void updated(Object instance, String name) { if (instance != null && !reinjectable) { throw new IllegalStateException("Implementation is not reinjectable: " + instance.getClass().getName()); } for (int i = 0; i < injectables.length; i++) { Injectable attribute = injectables[i]; if (attribute.getName().equals(name)) { Injector<Object> injector = injectors[i]; if (instance != null) { updatedInjectors.add(injector); } } } }
/** * Adds a callback proxy definition and its associated injection site * * @param definition the callback proxy definition * @param injectionSite the proxy injection site */ public void add(Callback definition, InjectionSite injectionSite) { definition.setParent(this); String name = definition.getName(); callbacks.put(name, definition); Injectable injectable = new Injectable(InjectableType.CALLBACK, name); addInjectionSite(injectionSite, injectable); injectionSiteMapping.put(definition, injectionSite); }
/** * Add the injection site for an injectable value. * * @param site the injection site * @param source the value to be injected */ public void addInjectionSite(InjectionSite site, Injectable source) { site.setParent(this); source.setParent(this); injectionSites.put(site, source); }
/** * Add a reference and its associated with an injection site. * * @param reference the reference to add * @param injectionSite the injection site for the reference */ public void add(Reference<ComponentType> reference, InjectionSite injectionSite) { super.add(reference); Injectable injectable = new Injectable(InjectableType.REFERENCE, reference.getName()); addInjectionSite(injectionSite, injectable); injectionSiteMapping.put(reference, injectionSite); }
/** * Add a property and its associated with an injection site. * * @param property the property to add * @param injectionSite the injection site for the property */ public void add(Property property, InjectionSite injectionSite) { super.add(property); Injectable injectable = new Injectable(InjectableType.PROPERTY, property.getName()); addInjectionSite(injectionSite, injectable); injectionSiteMapping.put(property, injectionSite); }
public void startUpdate() { for (Map.Entry<Injectable, Supplier<?>> entry : factories.entrySet()) { // signal to multiplicity factories that previous contents should be overwritten if the factory is updated (e.g. during reinjection) Injectable injectable = entry.getKey(); Supplier<?> factory = entry.getValue(); if (InjectableType.REFERENCE == injectable.getType() || InjectableType.CALLBACK == injectable.getType()) { if (factory instanceof MultiplicitySupplier) { MultiplicitySupplier<?> multiplicitySupplier = (MultiplicitySupplier<?>) factory; multiplicitySupplier.startUpdate(); } } } }
public void updated(Object instance, String name) { if (instance != null && !reinjectable) { throw new IllegalStateException("Implementation is not reinjectable: " + instance.getClass().getName()); } for (int i = 0; i < injectables.length; i++) { Injectable attribute = injectables[i]; if (attribute.getName().equals(name)) { Injector<Object> injector = injectors[i]; if (instance != null) { updatedInjectors.add(injector); } } } }
/** * Finds the mapped Supplier for the injectable. * * @param injectable the injectable * @return the Supplier */ private Supplier<?> findSupplier(Injectable injectable) { Supplier<?> supplier = null; for (Map.Entry<Supplier, Injectable> entry : reinjectionMappings.entrySet()) { if (injectable.equals(entry.getValue())) { supplier = entry.getKey(); break; } } return supplier; }
/** * Add a producer and its associated injection site. * * @param producer the producer to add * @param injectionSite the injection site for the producer */ public void add(Producer<ComponentType> producer, InjectionSite injectionSite) { super.add(producer); Injectable injectable = new Injectable(InjectableType.PRODUCER, producer.getName()); addInjectionSite(injectionSite, injectable); injectionSiteMapping.put(producer, injectionSite); }
public void endUpdate() { for (Map.Entry<Injectable, Supplier<?>> entry : factories.entrySet()) { // signal to multiplicity factories updates are complete Injectable injectable = entry.getKey(); Supplier<?> factory = entry.getValue(); if (InjectableType.REFERENCE == injectable.getType() || InjectableType.CALLBACK == injectable.getType()) { if (factory instanceof MultiplicitySupplier) { MultiplicitySupplier<?> multiplicitySupplier = (MultiplicitySupplier<?>) factory; multiplicitySupplier.endUpdate(); } } } }
public void removed(Object instance, String name) { if (instance != null && !reinjectable) { throw new IllegalStateException("Implementation is not reinjectable: " + instance.getClass().getName()); } for (int i = 0; i < injectables.length; i++) { Injectable attribute = injectables[i]; if (attribute.getName().equals(name)) { Injector<Object> injector = injectors[i]; injector.clearSupplier(); if (instance != null) { updatedInjectors.add(injector); } } } }
private InjectionSite findInjectionSite(Injectable attribute) { // try constructor for (int i = 0; i < cdiSources.size(); i++) { Injectable injectable = cdiSources.get(i); if (attribute.equals(injectable)) { return new ConstructorInjectionSite(constructor, i); } } // try postConstruction for (Map.Entry<InjectionSite, Injectable> entry : postConstruction.entrySet()) { if (entry.getValue().equals(attribute)) { return entry.getKey(); } } return null; }
/** * Add a resource reference and its associated an injection site. * * @param definition the resource reference to add * @param injectionSite the injection site for the resource */ public void add(ResourceReference definition, InjectionSite injectionSite) { super.add(definition); Injectable injectable = new Injectable(InjectableType.RESOURCE, definition.getName()); addInjectionSite(injectionSite, injectable); injectionSiteMapping.put(definition, injectionSite); }
public void startUpdate() { for (Map.Entry<Injectable, Supplier<?>> entry : factories.entrySet()) { // signal to multiplicity factories that previous contents should be overwritten if the factory is updated (e.g. during reinjection) Injectable injectable = entry.getKey(); Supplier<?> factory = entry.getValue(); if (InjectableType.REFERENCE == injectable.getType() || InjectableType.CALLBACK == injectable.getType()) { if (factory instanceof MultiplicitySupplier) { MultiplicitySupplier<?> multiplicitySupplier = (MultiplicitySupplier<?>) factory; multiplicitySupplier.startUpdate(); } } } }
public void removed(Object instance, String name) { if (instance != null && !reinjectable) { throw new IllegalStateException("Implementation is not reinjectable: " + instance.getClass().getName()); } for (int i = 0; i < injectables.length; i++) { Injectable attribute = injectables[i]; if (attribute.getName().equals(name)) { Injector<Object> injector = injectors[i]; injector.clearSupplier(); if (instance != null) { updatedInjectors.add(injector); } } } }
private InjectionSite findInjectionSite(Injectable attribute) { // try constructor for (int i = 0; i < cdiSources.size(); i++) { Injectable injectable = cdiSources.get(i); if (attribute.equals(injectable)) { return new ConstructorInjectionSite(constructor, i); } } // try postConstruction for (Map.Entry<InjectionSite, Injectable> entry : postConstruction.entrySet()) { if (entry.getValue().equals(attribute)) { return entry.getKey(); } } return null; }
/** * Add a consumer and its associated accessible object. * * @param consumer the consumer to add * @param object the consumer method, field or ctor */ public void add(Consumer<ComponentType> consumer, InjectionSite injectionSite, AccessibleObject object) { super.add(consumer); Injectable injectable = new Injectable(InjectableType.CONSUMER, consumer.getName()); addInjectionSite(injectionSite, injectable); injectionSiteMapping.put(consumer, injectionSite); consumerSignatures.put(consumer.getName(), object); }
@SuppressWarnings("unchecked") public void setSupplier(Injectable injectable, Supplier<?> supplier, InjectionAttributes attributes) { if (InjectableType.REFERENCE == injectable.getType() || InjectableType.CALLBACK == injectable.getType()) { setUpdatableFactory(injectable, supplier, attributes); } else { // the factory corresponds to a property or context, which will override previous values if re-injected Supplier<?> factory = factories.get(injectable); if (factory instanceof UpdatableSupplier) { ((UpdatableSupplier) factory).update(supplier); } else { factories.put(injectable, supplier); } } }