private ObjectAdapter initializePropertiesAndDoCallback(final ObjectAdapter adapter) { // initialize new object final List<ObjectAssociation> fields = adapter.getSpecification().getAssociations(Contributed.EXCLUDED); for (ObjectAssociation field : fields) { field.toDefault(adapter); } final Object pojo = adapter.getObject(); servicesInjector.injectServicesInto(pojo); CallbackFacet.Util.callCallback(adapter, CreatedCallbackFacet.class); if (Command.class.isAssignableFrom(pojo.getClass())) { // special case... the command object is created while the transaction is being started and before // the event bus service is initialized (nb: we initialize services *within* a transaction). To resolve // this catch-22 situation, we simply suppress the posting of this event for this domain class. // this seems the least unpleasant of the various options available: // * we could have put a check in the EventBusService to ignore the post if not yet initialized; // however this might hide other genuine errors // * we could have used the thread-local in JdoStateManagerForIsis and the "skip(...)" hook in EventBusServiceJdo // to have this event be skipped; but that seems like co-opting some other design // * we could have the transaction initialize the EventBusService as a "special case" before creating the Command; // but then do we worry about it being re-init'd later by the ServicesInitializer? // so, doing it this way is this simplest, least obscure. if(LOG.isDebugEnabled()) { LOG.debug("Skipping postEvent for creation of Command pojo"); } } else { postLifecycleEventIfRequired(adapter, CreatedLifecycleEventFacet.class); } return adapter; }
private Object createObject(final ObjectAdapter parent, final CreationMode creationMode) { if (getCorrespondingClass().isArray()) { return Array.newInstance(getCorrespondingClass().getComponentType(), 0); } try { final Object object = getObjectInstantiator().instantiate(getCorrespondingClass()); if (creationMode == CreationMode.INITIALIZE) { final ObjectAdapter adapter; if (parent == null) { adapter = getAdapterMap().adapterFor(object); } else { adapter = getAdapterMap().adapterForAggregated(object, parent); } // initialize new object final List<ObjectAssociation> fields = adapter.getSpecification().getAssociations(); for (int i = 0; i < fields.size(); i++) { fields.get(i).toDefault(adapter); } getDependencyInjector().injectDependenciesInto(object); CallbackUtils.callCallback(adapter, CreatedCallbackFacet.class); } return object; } catch (final ObjectInstantiationException e) { throw new IsisException("Failed to create instance of type " + getFullIdentifier(), e); } }