view src/org/dancres/blitz/tools/ReconfigLookup.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.tools;

import org.dancres.blitz.remote.LookupStorage;
import org.dancres.blitz.config.ConfigurationFactory;
import org.dancres.blitz.disk.Disk;

/**
 * Reimport specified lookup data from specified configuration
 */
public class ReconfigLookup {
    private static String[] OPTIONS =
        new String[] {"-attrs", "-locators", "-groups"};

    private static byte[] FLAGS =
        new byte[] {LookupStorage.INIT_ATTRS, LookupStorage.INIT_LOCATORS,
            LookupStorage.INIT_GROUPS};

    public static void main(String anArgs[]) throws Exception {
        if (anArgs.length < 2) {
            System.err.println(
                "Usage: blitz_config_URL [-attrs | -locators | -groups]+ ");
        }

        String[] myURL = new String[] {anArgs[0]};
        byte myFlags = 0;

        for (int i = 1; i < anArgs.length; i++) {
            myFlags = (byte) (myFlags | convert(anArgs[i]));
        }

        ConfigurationFactory.setup(myURL);

        Disk.init();

        LookupStorage myStorage = new LookupStorage();
        myStorage.reinit(ConfigurationFactory.getConfig(), myFlags);
        myStorage.saveState();

        Disk.sync();
        Disk.stop();
    }

    private static byte convert(String anOption)
        throws IllegalArgumentException {

        for (int i = 0; i < OPTIONS.length; i++) {
            if (OPTIONS[i].equals(anOption))
                return FLAGS[i];
        }

        throw new IllegalArgumentException("Invalid option: " + anOption);
    }
}