view src/org/dancres/blitz/meta/RegistryFactory.java @ 27:511648fa4d64 Version 2.1

Version to 2.1
author Dan Creswell <dan.creswell@gmail.com>
date Mon, 04 Jan 2010 13:00:40 +0000
parents 3dc0c5604566
children
line wrap: on
line source

package org.dancres.blitz.meta;

import java.io.File;
import java.io.IOException;

import java.util.Map;
import java.util.HashMap;

import org.dancres.blitz.disk.Disk;

public class RegistryFactory {
    private static Map theMetas = new HashMap();

    /**
       @param aName the name of the registry you wish to load/create
       @param anInitializer Registry instances are created under a transaction.
       Certain uses may require that initialization be done under the same
       transaction.  In these cases, the caller should pass in an Initializer
       instance containing the appropriate "boot code".  If no initialization
       is required, the caller may pass <code>null</code>.
     */
    public static Registry get(String aName, Initializer anInitializer)
        throws IOException {

        synchronized(theMetas) {
            Registry myData = (Registry) theMetas.get(aName);

            if (myData == null) {
                myData = new RegistryImpl(aName, anInitializer);
                theMetas.put(aName, myData);
            }

            return myData;
        }
    }

    public static boolean exists(String aName) {
        return RegistryImpl.exists(aName);
    }

    public static void delete(String aName) throws IOException {
        synchronized(theMetas) {
            RegistryImpl myData = (RegistryImpl) theMetas.get(aName);

            if (myData != null) {
                theMetas.remove(aName);
                myData.delete();
            }
        }
    }
}