// MirrorRegistry.java
//
// Created: December 2005
//
// This file is a component of the BioMoby project.
// Copyright Martin Senger (martin.senger@gmail.com).
//

import org.biomoby.shared.*;
import org.biomoby.client.CmdLineHelper;
import org.biomoby.client.CentralImpl;
import org.biomoby.shared.Central;

import org.tulsoft.tools.BaseCmdLine;
import org.tulsoft.shared.FileUtils;
import org.tulsoft.shared.GException;

import java.util.Iterator;
import java.util.Map;

/**
 * !!!WORK IN PROGRES!!! <p>
 *
 * @author <A HREF="mailto:martin.senger@gmail.com">Martin Senger</A>
 * @version $Id: MirrorRegistry.java,v 1.3 2008/02/23 13:58:32 senger Exp $
 */

public class MirrorRegistry
    extends CmdLineHelper {

    /*************************************************************************
     *
     * Entry point...
     *
     *************************************************************************/
    public static void main (String [] args) {
	try {

	    BaseCmdLine cmd = getCmdLine (args, MirrorRegistry.class);

	    // where are Moby registries
	    String eTo = cmd.getParam ("-eTo");
	    if (eTo == null) {
		System.err.println ("Parameter -eTo must be specified.");
		System.exit (1);
	    }
	    String uriTo = cmd.getParam ("-uriTo");
	    if (uriTo == null) {
		System.err.println ("Parameter -uriTo must be specified.");
		System.exit (1);
	    }
	    Central workerFrom = new CentralImpl (cmd.getParam ("-e"),
						  cmd.getParam ("-uri"));
	    Central workerTo = new CentralImpl (eTo, uriTo);

	    // do it for data types
	    Map dtNamesFrom = workerFrom.getDataTypeNames();
	    Map dtNamesTo = workerTo.getDataTypeNames();

	    for (Iterator it = dtNamesFrom.keySet().iterator(); it.hasNext(); ) {
		String name = (String)it.next();
		if (! dtNamesTo.containsKey (name)) {
		    System.out.println ("Updating " + name);
		    MobyDataType newDataType = workerFrom.getDataType (name);
		    workerTo.registerDataType (newDataType);
		}
	    }

	    // do it for namespaces
	    // do it for service types
	    // do it for services

	} catch (Exception e) {
	    System.err.println ("===ERROR===");
	    e.printStackTrace();
	    System.err.println ("===========");
	}
    }

    /*************************************************************************
     * Print 'msg' but only if in verbose mode
     *************************************************************************/
    static void decoration (String msg) {
 	if (verbose) System.out.print (msg);
    }
    static void decorationLn (String msg) {
 	if (verbose) System.out.println (msg);
    }

}
