Package org.apache.slide.content

Source Code of org.apache.slide.content.NodeRevisionDescriptors

/*
* $Header: /home/cvs/jakarta-slide/src/share/org/apache/slide/content/NodeRevisionDescriptors.java,v 1.7 2001/10/12 01:30:38 remm Exp $
* $Revision: 1.7 $
* $Date: 2001/10/12 01:30:38 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation.  All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in
*    the documentation and/or other materials provided with the
*    distribution.
*
* 3. The end-user documentation included with the redistribution, if
*    any, must include the following acknowlegement:
*       "This product includes software developed by the
*        Apache Software Foundation (http://www.apache.org/)."
*    Alternately, this acknowlegement may appear in the software itself,
*    if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
*    Foundation" must not be used to endorse or promote products derived
*    from this software without prior written permission. For written
*    permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
*    nor may "Apache" appear in their names without prior written
*    permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation.  For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/

package org.apache.slide.content;

import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import java.util.StringTokenizer;
import org.apache.slide.common.*;
import org.apache.slide.util.Messages;

/**
* Node Revision Descriptors class.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @version $Revision: 1.7 $
*/
public final class NodeRevisionDescriptors implements Serializable, Cloneable {
   
   
    // -------------------------------------------------------------- Constants
   
   
    public static final String MAIN_BRANCH = "main";
   
   
    protected static final NodeRevisionNumber initialRevision
        = new NodeRevisionNumber();
   
   
    // ----------------------------------------------------------- Constructors
   
   
    /**
     * Client side constructor.
     */
    public NodeRevisionDescriptors() {
        this.latestRevisionNumbers = new Hashtable();
        this.branches = new Hashtable();
        this.workingRevisions = new Hashtable();
        this.useVersioning = false;
    }
   
   
    /**
     * Client side constructor.
     */
    public NodeRevisionDescriptors(boolean isVersioned) {
        this.latestRevisionNumbers = new Hashtable();
        this.branches = new Hashtable();
        this.workingRevisions = new Hashtable();
        this.useVersioning = isVersioned;
    }
   
   
    /**
     * Store Constructor.
     */
    public NodeRevisionDescriptors(String uri,
                                   NodeRevisionNumber initialRevision,
                                   Hashtable workingRevisions,
                                   Hashtable latestRevisionNumbers,
                                   Hashtable branches, boolean isVersioned) {
        this.uri = uri;
        this.latestRevisionNumbers = latestRevisionNumbers;
        this.branches = branches;
        this.workingRevisions = workingRevisions;
        this.useVersioning = isVersioned;
    }
   
   
    // ----------------------------------------------------- Instance Variables
   
   
    /**
     * Use versioning.
     */
    private boolean useVersioning;
   
   
    /**
     * Uri.
     */
    private String uri;
   
   
    /**
     * Working revisions.
     */
    private Hashtable workingRevisions;
   
   
    /**
     * Latest revision numbers.
     */
    private Hashtable latestRevisionNumbers;
   
   
    /**
     * Branches.
     */
    private Hashtable branches;
   
   
    // ------------------------------------------------------------- Properties
   
   
    /**
     * Use versioning accessor.
     */
    public boolean isVersioned() {
        return this.useVersioning;
    }
   
   
    /**
     * Use versioning mutator.
     */
    void setVersioned(boolean useVersioning) {
        this.useVersioning = useVersioning;
    }
   
   
    /**
     * Has revision ?
     */
    public boolean hasRevisions() {
        return !(this.latestRevisionNumbers.isEmpty());
    }
   
   
    /**
     * Uri accessor.
     */
    public String getUri() {
        return this.uri;
    }
   
   
    /**
     * Uri mutator.
     */
    void setUri(String uri) {
        this.uri = uri;
    }
   
   
    /**
     * Get initial revision.
     */
    public NodeRevisionNumber getInitialRevision() {
        return this.initialRevision;
    }
   
   
    /**
     * Get latest revision from main branch.
     */
    public NodeRevisionNumber getLatestRevision() {
        return getLatestRevision(MAIN_BRANCH);
    }
   
   
    /**
     * Get latest revision from a branch.
     */
    public NodeRevisionNumber getLatestRevision(String branchName) {
        Object number = null;
        number = this.latestRevisionNumbers.get(branchName);
        if (number != null) {
            return (NodeRevisionNumber) number;
        } else {
            return null;
        }
    }
   
   
    /**
     * Latest revision mutator.
     */
    void setLatestRevision(NodeRevisionNumber number) {
        this.latestRevisionNumbers.put(MAIN_BRANCH, number);
    }
   
   
    /**
     * Latest revision mutator.
     */
    void setLatestRevision(String branch, NodeRevisionNumber number) {
        this.latestRevisionNumbers.put(branch, number);
    }
   
   
    // --------------------------------------------------------- Public Methods
   
   
    /**
     * Get relations.
     */
    public Enumeration getSuccessors(NodeRevisionNumber number) {
        Object result = this.branches.get(number);
        if (result != null) {
            return ((Vector) result).elements();
        } else {
            return null;
        }
    }
   
   
    // -------------------------------------------------------- Package Methods
   
   
    /**
     * Add relation.
     */
    void setSuccessors(NodeRevisionNumber number,
                       NodeRevisionNumber successor) {
        Vector tempVector = new Vector();
        tempVector.addElement(successor);
        setSuccessors(number, tempVector);
    }
   
   
    /**
     * Add relation.
     */
    void setSuccessors(NodeRevisionNumber number, Vector successors) {
        this.branches.put(number, successors);
    }
   
   
    /**
     * Add relation.
     */
    void addSuccessor(NodeRevisionNumber number,
                      NodeRevisionNumber successor) {
        Object result = this.branches.get(number);
        if (result != null) {
            ((Vector) result).addElement(successor);
        } else {
            setSuccessors(number, successor);
        }
    }
   
   
    /**
     * Remove relation.
     */
    void removeSuccessor(NodeRevisionNumber number,
                         NodeRevisionNumber successor) {
        Object result = this.branches.get(number);
        if (result != null) {
            ((Vector) result).removeElement(successor);
        }
    }
   
   
    /**
     * Enumerate all revision numbers in all branches.
     */
    public Enumeration enumerateRevisionNumbers() {
        return this.branches.keys();
    }
   

    /**
     * Enumerate all branch names.
     */
   public Enumeration enumerateBranchNames() {
     return this.latestRevisionNumbers.keys();
   }

   
   
   
    // --------------------------------------------------------- Object Methods
   
   
    /**
     * Clone.
     *
     * @return Object clone
     */
    public NodeRevisionDescriptors cloneObject() {
        NodeRevisionDescriptors result = null;
        try {
            result = (NodeRevisionDescriptors) super.clone();
            // TODO : No cloning of the working revisions list for now
            // Cloning branches
            Hashtable branchesClone = new Hashtable();
            Enumeration branchesList = this.branches.keys();
            while (branchesList.hasMoreElements()) {
                Object key = branchesList.nextElement();
                Vector value = (Vector) this.branches.get(key);
                branchesClone.put(key, value.clone());
            }
            result.branches = branchesClone;
            // Cloning latest revision list
            result.latestRevisionNumbers =
                (Hashtable) this.latestRevisionNumbers.clone();
        } catch(CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return result;
    }
   
   
    /**
     * Equals.
     *
     * @param obj Object to test
     * @return boolean True if the two object are equal :
     * <li>obj is of type NodeRevisionDescriptors and is not null</li>
     * <li>it has the same Uri</li>
     */
    public boolean equals(Object obj) {
        boolean result = false;
        if ((obj != null) && (obj instanceof NodeRevisionDescriptors)) {
            NodeRevisionDescriptors revisionDescriptors =
                (NodeRevisionDescriptors) obj;
            result = this.getUri().equals(revisionDescriptors.getUri());
        }
        return result;
    }
   
   
    /**
     * Validate.
     */
    public void validate(String expectedUri) {
       
        if (uri == null)
            throw new ObjectValidationFailedException
                (expectedUri, Messages.message
                 (NodeRevisionDescriptors.class.getName() + ".nullUri"));
       
        if (!(uri.equals(expectedUri) || uri.equals(expectedUri + "/"))) {
            System.out.println("Uri1 : " + uri + " Uri2 : " + expectedUri);
            //throw new ObjectValidationFailedException
            //(expectedUri, Messages.message
            //(NodeRevisionDescriptors.class.getName() + ".incorrectUri"));
        }
       
        if (workingRevisions == null)
            throw new ObjectValidationFailedException
                (uri, Messages.message
                 (NodeRevisionDescriptors.class.getName()
                  + ".nullWorkingRevisions"));
       
        if (latestRevisionNumbers == null)
            throw new ObjectValidationFailedException
                (uri, Messages.message
                 (NodeRevisionDescriptors.class.getName()
                  + ".nullLatestRevisionNumbers"));
       
        if (branches == null)
            throw new ObjectValidationFailedException
                (uri, Messages.message
                 (NodeRevisionDescriptors.class.getName()
                  + ".nullBranches"));
       
        // FIXME : Check branches integrity. Problem : It's quite expensive.
       
    }
   
   
}

TOP

Related Classes of org.apache.slide.content.NodeRevisionDescriptors

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.