Package com.dbxml.db.enterprise.sync

Source Code of com.dbxml.db.enterprise.sync.Manifest

package com.dbxml.db.enterprise.sync;

/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: Manifest.java,v 1.3 2006/02/02 19:04:15 bradford Exp $
*/

import java.util.*;

import com.dbxml.labrador.types.Variant;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
* Manifest represents a Content update manifest.
*/

public final class Manifest {
   private static final String[] EmptyStrings = new String[0];

   private Date date;
   private Map content = Collections.synchronizedMap(new TreeMap()); // String to Content
   private Map groups = Collections.synchronizedMap(new TreeMap())// String to GroupInfo

   public Manifest(Document doc) {
      this(doc.getDocumentElement());
   }

   public Manifest(Element elem) {
      date = new Variant(elem.getAttribute(Constants.DATE)).getDate();

      NodeList nl = elem.getChildNodes();
      for ( int i = 0; i < nl.getLength(); i++ ) {
         Node n = nl.item(i);
         if ( n.getNodeType() == Node.ELEMENT_NODE ) {
            Element groupElem = (Element)n;
            if ( groupElem.getTagName().equals(Constants.GROUP) ) {
               String name = groupElem.getAttribute(Constants.NAME);
               double version = Double.parseDouble(groupElem.getAttribute(Constants.VERSION));
               int status = Constants.getStatusValue(groupElem.getAttribute(Constants.VERSION));
               GroupInfo gi = new GroupInfo(name, version, status);
               groups.put(name, gi);
  
               NodeList el = groupElem.getChildNodes();
               for ( int j = 0; j < el.getLength(); j++ ) {
                  Node en = el.item(j);
                  if ( en.getNodeType() == Node.ELEMENT_NODE ) {
                     Element contentElem = (Element)en;
                     if ( contentElem.getTagName().equals(Constants.CONTENT) ) {
                        Content c = new Content();
                        c.streamFromXML(contentElem);
                        String path = c.getPath();
                        content.put(path, c);
                        gi.addContent(path);
                     }
                  }
               }
            }
         }
      }
   }

   public Date getDate() {
      return date;
   }

   public void setDate(Date date) {
      this.date = date;
   }

   public Content getContent(String path) {
      return (Content)content.get(path);
   }

   public String[] getGroupNames() {
      return (String[])groups.keySet().toArray(EmptyStrings);
   }

   public double getGroupVersion(String group) {
      GroupInfo gi = (GroupInfo)groups.get(group);
      if ( group != null )
         return gi.version;
      else
         return 0.0;
   }

   public int getGroupStatus(String group) {
      GroupInfo gi = (GroupInfo)groups.get(group);
      if ( group != null )
         return gi.status;
      else
         return Constants.STATUS_UNKNOWN;
   }

   public String[] getGroupContent(String group) {
      GroupInfo gi = (GroupInfo)groups.get(group);
      if ( group != null )
         return (String[])gi.content.toArray(EmptyStrings);
      else
         return EmptyStrings;
   }


   /**
    * GroupInfo
    */

   private class GroupInfo {
      public String name;
      public double version;
      public int status;
      public Set content = new TreeSet();

      public GroupInfo(String name, double version, int status) {
         this.name = name;
         this.version = version;
         this.status = status;
      }

      public void addContent(String path) {
         content.add(path);
      }
   }
}
TOP

Related Classes of com.dbxml.db.enterprise.sync.Manifest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.