initializing = true;
status = INITIALIZING;
	protected void initialize() throws EXistException {        if (LOG.isDebugEnabled())            LOG.debug("initializing database instance '" + instanceName + "'...");                //Flag to indicate that we are initializing		initializing = true;        		//REFACTOR : construct then configure        cacheManager = new CacheManager(conf);        //REFACTOR : construct then configure        xQueryPool = new XQueryPool(conf);        //REFACTOR : construct then... configure        xQueryMonitor = new XQueryMonitor();        //REFACTOR : construct then... configure        xmlReaderPool = new XMLReaderPool(new XMLReaderObjectFactory(this), 5, 0);        //REFACTOR : construct then... configure        int bufferSize = conf.getInteger(PROPERTY_COLLECTION_CACHE_SIZE);        if(bufferSize == -1)        	bufferSize = DEFAULT_COLLECTION_BUFFER_SIZE;        collectionCache = new CollectionCache(this, bufferSize, 0.9);                notificationService = new NotificationService();                //REFACTOR : construct then... configure        //TODO : journal directory *may* be different from "db-connection.data-dir"        transactionManager = new TransactionManager(this, new File((String) conf.getProperty("db-connection.data-dir")), isTransactional());		        try {            transactionManager.initialize();        } catch (ReadOnlyException e) {            LOG.warn(e.getMessage() + ". Switching to read-only mode!!!");            isReadOnly = true;        }                //TODO : replace the following code by get()/release() statements ?        // WM: I would rather tend to keep this broker reserved as a system broker.        // create a first broker to initialize the security manager		createBroker();		//TODO : this broker is *not* marked as active and *might* be reused by another process ! Is it intended ?        // at this stage, the database is still single-threaded, so reusing the broker later is not a problem.		DBBroker broker = (DBBroker) inactiveBrokers.peek();                if (broker.isReadOnly()) {            transactionManager.setEnabled(false);            isReadOnly = true;        }        		//Run the recovery process        //TODO : assume         boolean recovered = false;		if (isTransactional()) {			recovered = transactionManager.runRecovery(broker);            //TODO : extract the following from this block ? What if we ware not transactional ? -pb             if (!recovered) {            	if (broker.getCollection(XmldbURI.ROOT_COLLECTION_URI) == null) {            		Txn txn = transactionManager.beginTransaction();            		try {            			//TODO : use a root collection final member            			broker.getOrCreateCollection(txn, XmldbURI.ROOT_COLLECTION_URI);            			transactionManager.commit(txn);            		} catch (PermissionDeniedException e) {            			transactionManager.abort(txn);            		}            	}            }        }                //TODO : from there, rethink the sequence of calls.        // WM: attention: a small change in the sequence of calls can break        // either normal startup or recovery.                // remove temporary docs		broker.cleanUpTempCollection();                //create the security manager		//TODO : why only the first broker has a security manager ? Global or attached to each broker ?        // WM: there's only one security manager per BrokerPool, but it needs a DBBroker instance to read        // the system collection.		SecurityManager localSecurityManager = newSecurityManager();		securityManager = null;		localSecurityManager.attach(this, broker);		securityManager = localSecurityManager;		initializing = false;		//have to do this after initializing = false		// so that the policies collection is saved		if(securityManager.isXACMLEnabled())			securityManager.getPDP().initializePolicyCollection();		//Get a manager to handle further collectios configuration		collectionConfigurationManager = new CollectionConfigurationManager(broker);                //If necessary, launch a task to repair the DB        //TODO : merge this with the recovery process ?        if (recovered) {            try {                broker.setUser(SecurityManager.SYSTEM_USER);                broker.repair();            } catch (PermissionDeniedException e) {                LOG.warn("Error during recovery: " + e.getMessage(), e);            }        }		        //Create the minimal number of brokers required by the configuration 		for (int i = 1; i < minBrokers; i++)			createBroker();        		//Schedule the system tasks	            	    for (int i = 0; i < systemTasks.size(); i++) {	    	//TODO : remove first argument when SystemTask has a getPeriodicity() method	        initSystemTask((Long)systemTasksPeriods.elementAt(i), (SystemTask)systemTasks.get(i));	    }				        if (LOG.isDebugEnabled())            LOG.debug("database instance '" + instanceName + "' initialized");	}