package com.dbxml.db.enterprise.sync;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: SyncManagerClient.java,v 1.4 2004/02/12 00:17:57 bradford Exp $
 */

import com.dbxml.db.client.dbXMLClient;
import com.dbxml.db.client.xmlrpc.ConnectionManager;
import com.dbxml.util.dbXMLException;
import com.dbxml.xml.dom.DOMHelper;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * SyncManagerClient
 */

public final class SyncManagerClient extends ConnectionManager {
   private static final String PATH = "/system/syncmanager";

   public SyncManagerClient(dbXMLClient dbxmlClient) {
      super(dbxmlClient);
      setClientPath(PATH);
   }

   public String getMachineID() throws dbXMLException {
      return executeString("getMachineID", null);
   }

   public void addGroup(String group) throws dbXMLException {
      execute("addGroup", new Object[]{group});
   }

   public void removeGroup(String group) throws dbXMLException {
      execute("removeGroup", new Object[]{group});
   }

   public String[] listGroups() throws dbXMLException {
      return executeList("listGroups", null);
   }

   public void addCollection(String group, String collection) throws dbXMLException {
      execute("addCollection", new Object[]{group, collection});
   }

   public void removeCollection(String group, String collection) throws dbXMLException {
      execute("removeCollection", new Object[]{group, collection});
   }

   public String[] listCollections(String group) throws dbXMLException {
      return executeList("listCollections", new Object[]{group});
   }

   public void addGroupToContent(String path, String group) throws dbXMLException {
      execute("addGroupToContent", new Object[]{path, group});
   }

   public void removeGroupFromContent(String path, String group) throws dbXMLException {
      execute("removeGroupFromContent", new Object[]{path, group});
   }

   public String[] listContentGroups(String path) throws dbXMLException {
      return executeList("listContentGroups", new Object[]{path});
   }

   public String[] listGroupContents(String group) throws dbXMLException {
      return executeList("listGroupContents", new Object[]{group});
   }

   public Manifest listGroupChanges(Date date, String[] groups) throws dbXMLException {
      try {
         List groupList = new ArrayList(groups.length);
         for ( int i = 0; i < groups.length; i++ )
            groupList.add(groups[i]);
         String doc = executeString("listGroupChanges", new Object[]{date, groupList});
         return new Manifest(DOMHelper.parseText(doc));
      }
      catch ( dbXMLException e ) {
         throw e;
      }
      catch ( Exception e ) {
         throw new dbXMLException(e);
      }
   }

   public Manifest listAllChanges(Date date) throws dbXMLException {
      try {
         String doc = executeString("listAllChanges", new Object[]{date});
         return new Manifest(DOMHelper.parseText(doc));
      }
      catch ( dbXMLException e ) {
         throw e;
      }
      catch ( Exception e ) {
         throw new dbXMLException(e);
      }
   }
}

