public void updated(Object instance, String referenceName) { if (instance != null && !reinjectable) { throw new IllegalStateException("Implementation is not reinjectable: " + componentUri); } for (int i = 0; i < injectables.length; i++) { Injectable attribute = injectables[i]; if (attribute.getName().equals(referenceName)) { Injector<Object> injector = injectors[i]; if (instance != null) { updatedInjectors.add(injector); } } } }
public void removed(Object instance, String referenceName) { if (instance != null && !reinjectable) { throw new IllegalStateException("Implementation is not reinjectable: " + componentUri); } for (int i = 0; i < injectables.length; i++) { Injectable attribute = injectables[i]; if (attribute.getName().equals(referenceName)) { Injector<Object> injector = injectors[i]; injector.clearObjectFactory(); if (instance != null) { updatedInjectors.add(injector); } } } }
private void generateReferenceInjectionMapping(AbstractReference definition, WebComponentType type, Map<String, Map<String, InjectionSite>> mappings) { Map<String, InjectionSite> mapping = mappings.get(definition.getName()); if (mapping == null) { mapping = new HashMap<String, InjectionSite>(); mappings.put(definition.getName(), mapping); } for (Map.Entry<String, Map<InjectionSite, Injectable>> entry : type.getInjectionSites().entrySet()) { for (Map.Entry<InjectionSite, Injectable> siteMap : entry.getValue().entrySet()) { if (siteMap.getValue().getName().equals(definition.getName())) { mapping.put(entry.getKey(), siteMap.getKey()); } } } ServiceContract contract = definition.getServiceContract(); String interfaceClass = contract.getQualifiedInterfaceName(); // inject the reference into the session context WebContextInjectionSite site = new WebContextInjectionSite(interfaceClass, SESSION_CONTEXT); mapping.put(SESSION_CONTEXT_SITE, site); // also inject the reference into the servlet context WebContextInjectionSite servletContextsite = new WebContextInjectionSite(interfaceClass, SERVLET_CONTEXT); mapping.put(SERVLET_CONTEXT_SITE, servletContextsite); }
public void removeObjectFactory(Injectable injectable) { factory.removeObjectFactory(injectable); String name = injectable.getName(); List<Object> instances = scopeContainer.getActiveInstances(this); for (Object instance : instances) { getImplementationManager().removed(instance, name); } // Clear the instance factory as it has changed and will need to be re-created. This can happen if reinjection occurs after the first // instance has been created. recreate.set(true); }
/** * Sets an object factory. * * @param injectable the injectable identifying the component reference, property or context artifact the object factory creates instances for * @param objectFactory the object factory * @param attributes the injection attributes */ public void setObjectFactory(Injectable injectable, ObjectFactory<?> objectFactory, InjectionAttributes attributes) { factory.setObjectFactory(injectable, objectFactory, attributes); List<Object> instances = scopeContainer.getActiveInstances(this); String name = injectable.getName(); for (Object instance : instances) { getImplementationManager().updated(instance, name); } // Clear the instance factory as it has changed and will need to be re-created. This can happen if reinjection occurs after the first // instance has been created. recreate.set(true); }