/** * removes an object from the context and fires the remove event. * * @return previous object associated with the given name, or null if there was no mapping for this name. */ public Object remove(final String objectName) { Object removed = null; if (cache != null) { removed = cache.remove(objectName); fireObjectEvent(Descriptor.EVENT_REMOVE, objectName, removed); } return removed; }
Object construct(final Descriptor descriptor) { Object object; final String objectName = descriptor.getName(); if (objectName != null) { fireObjectEvent(Descriptor.EVENT_CONSTRUCTING, objectName, null); if (underConstruction == null) { underConstruction = new HashSet<String>(); } underConstruction.add(objectName); if (LOG.isLoggable(Level.FINE)) { LOG.fine("constructing " + objectName); } } try { object = descriptor.construct(this); } catch (final RuntimeException e) { addException(descriptor, e); throw e; } if (objectName != null) { underConstruction.remove(objectName); } return object; }
void performInitialization(final Object object, final Descriptor descriptor) { final String objectName = descriptor.getName(); if (objectName != null) { fireObjectEvent(Descriptor.EVENT_INITIALIZING, objectName, object); if (underInitialization == null) { underInitialization = new HashMap<String, Object>(); } underInitialization.put(objectName, object); if (LOG.isLoggable(Level.FINE)) { LOG.fine("initializing " + objectName); } } try { descriptor.initialize(object, this); } catch (final RuntimeException e) { addException(descriptor, e); throw e; } if (objectName != null) { underInitialization.remove(objectName); // event constructed is fired before the object is put in the cache // because that generates a set event fireObjectEvent(Descriptor.EVENT_CONSTRUCTED, objectName, object); set(objectName, object); } }
/** * adds an object to this context, which means storing it in the cache. This doesn't have to be an object that is * defined by the {@link WireDefinition}. If an object is set under a certain objectName that also is associated with * a descriptor, the object provided in this set invocation will be delivered upon subsequent {@link #get(String)} * requests. * * @return previous value of the object with the name objectName in the {@link #cache} * @throws WireException * when the objectName is null */ @Override public synchronized Object set(final String objectName, final Object object) { if (objectName == null) { final String message = ExceptionManager.getInstance().getFullMessage("bp_WC_1"); throw new WireException(message); } if (cache == null) { cache = new HashMap<String, Object>(); } fireObjectEvent(Descriptor.EVENT_SET, objectName, object); return cache.put(objectName, object); }