We have written a file descriptor store for slide.

It's based on the Remy's MemoryDescriptorsStore, but instead of using
a hashtable for each kind of attributes (permissions,locks,...),
we defined a hashtable of "UriProperties".

UriProperties encapsulates : 
        object
        permissions
        locks
        revisionDescriptors,...
and is store in XML format with JDOM.

We've tested it with :
        DAVExplorer 0.80
        Mac OS X (work for drag and drop, folder creation).

We are testing it in our application.
The slide configuration file slide.def we use :
slide.def

    <store name="Fichiers">
      <lockstore>
        <reference store="nodestore" />
      </lockstore>
      <nodestore classname="slidestore.file.XMLMemDescriptorsStore">
        <parameter name="rootpath">/TestsWebDAV</parameter>
      </nodestore>
      <securitystore>
        <reference store="nodestore" />
      </securitystore>
      <revisiondescriptorsstore>
        <reference store="nodestore" />
      </revisiondescriptorsstore>
      <revisiondescriptorstore>
        <reference store="nodestore" />
      </revisiondescriptorstore>
      <contentstore classname="slidestore.reference.FileContentStore">
        <parameter name="rootpath">/TestsWebDAV/contentstore</parameter>
        <parameter name="resetBeforeStarting">false</parameter>
      </contentstore>
    </store>


-- 
Marc DECUGIS, Modelisation Design Simulation
e-mail: [EMAIL PROTECTED]
tel : (33) 04 78 54 62 96
fax : (33) 04 78 54 63 57
/*
 * $Header$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 *
 * 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 [EMAIL PROTECTED]
 *
 * 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 slidestore.file;

//----------------------------------------
import java.util.*;
import java.io.*;
import org.apache.slide.common.*;
import org.apache.slide.store.*;
import org.apache.slide.structure.*;
import org.apache.slide.security.*;
import org.apache.slide.lock.*;
import org.apache.slide.content.*;
//----------------------------------------

//----------------------------------------
//----------------------------------------
//----------------------------------------
/**
  * Handles the descriptions attached to an Uri</a>
 * @author <a href="mailto:[EMAIL PROTECTED]";>Marc D�cugis</a>
 * @contact <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a> 
 * @version $Revision$ , $Date$
*/

//----------------------------------------
public class AbstractUriProperties  {
	
	
	/** Stored object.*/
	protected ObjectNode object;
	
	/** Permissions vector. */
	protected Vector permissions;
	
	/** Locks vector.*/
	protected Vector locks;
	
	/** Revision descriptors.*/
	protected NodeRevisionDescriptors revisionDescriptors;
	
	/** Revision descriptor hashtable.*/
	protected Hashtable descriptor;
	
	/** The rootpath user to store uri descriptions.*/
	protected String rootpath;
	
	
	
	//----------------------------------------
	public AbstractUriProperties(String aRootPath,Uri aUri) {
		rootpath=aRootPath;
	}
	//----------------------------------------
	protected void save(Uri aUri) throws ServiceAccessException {
		System.out.println("------------------------------------------------------------------------");
		System.out.println("----------- AbstractUriProperties save aUri="+aUri);
		System.out.println("----------- AbstractUriProperties save object="+object);
		System.out.println("----------- AbstractUriProperties save permissions="+permissions);
		System.out.println("----------- AbstractUriProperties save locks="+locks);
		System.out.println("----------- AbstractUriProperties save revisionDescriptors="+revisionDescriptors);
		System.out.println("----------- AbstractUriProperties save descriptor="+descriptor);
		System.out.println("------------------------------------------------------------------------");
	}
   
	//----------------------------------------
	//----------------------------------------
	//----------------------------------------
	
	//----------------------------------------
	/**
	* Retrive an object from the Descriptors Store.
	*
	* @param uri Uri of the object we want to retrieve
	* @exception ServiceAccessException Error accessing the Descriptors Store
	* @exception ObjectNotFoundException The object to retrieve was not found
	*/
	//----------------------------------------
	public ObjectNode retrieveObject(Uri uri)
        throws ServiceAccessException, ObjectNotFoundException {
		System.out.println("----------- AbstractUriProperties retrieveObject uri="+uri+" object="+object);
        if (object == null) {
            throw new ObjectNotFoundException(uri);
        }
		System.out.println("----------- AbstractUriProperties retrieveObject uri="+uri+" object="+object);
        return object.cloneObject();
    }

	//----------------------------------------
	/**
	* Store an object in the Descriptors Store.
	*
	* @param object Object to update
	* @exception ServiceAccessException Error accessing the Descriptors Store
	* @exception ObjectNotFoundException The object to update was not found
	*/
	//----------------------------------------
    public void storeObject(Uri uri,ObjectNode aObject)
        throws ServiceAccessException, ObjectNotFoundException {
		System.out.println("----------- AbstractUriProperties storeObject uri="+uri+" object="+object);
        object=aObject.cloneObject();
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Create a new object in the Descriptors Store.
	*
	* @param object SlideObject
	* @param uri Uri of the object we want to create
	* @exception ServiceAccessException Error accessing the Descriptors Store
	* @exception ObjectAlreadyExistsException An object already exists
	* at this Uri
	*/
	//----------------------------------------
    public void createObject(Uri uri,ObjectNode aObject)
        throws ServiceAccessException, ObjectAlreadyExistsException {
        try {
            if (object.getUri().equals(uri.toString())) {
                throw new ObjectAlreadyExistsException(uri.toString());
            }
            storeObject(uri,aObject);
        } catch(ObjectNotFoundException e) {
            // Never happens
        }
		System.out.println("----------- AbstractUriProperties createObject uri="+uri+" object="+object);
    }
	//----------------------------------------
	/**
	* Remove an object from the Descriptors Store.
	*
	* @param object Object to remove
	* @exception ServiceAccessException Error accessing the Descriptors Store
	* @exception ObjectNotFoundException The object to remove was not found
	*/
	//----------------------------------------
	public void removeObject(Uri uri, ObjectNode aObject)
        throws ServiceAccessException, ObjectNotFoundException {
        object=null;
		System.out.println("----------- AbstractUriProperties removeObject uri="+uri+" object="+object);
    }
        
	//----------------------------------------
	/**
	* Store an object permissions in the Descriptors Store.
	*
	* @param permission Permission we want to create
	* @exception ServiceAccessException Error accessing the Descriptors Store
	*/
	//----------------------------------------
    public void grantPermission(Uri uri,NodePermission permission)
        throws ServiceAccessException {
        if (permissions == null) permissions = new Vector();
        permissions.addElement(permission.cloneObject());
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Store an object permissions in the Descriptors Store.
	*
	* @param permission Permission we want to create
	* @exception ServiceAccessException Error accessing the Descriptors Store
	*/
	//----------------------------------------
    public void revokePermission(Uri uri,NodePermission permission)
        throws ServiceAccessException {
        if (permissions != null) 
			permissions.removeElement(permission);
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Revoke all the permissions on the object .
	*
	* @param permission Permission we want to create
	* @exception ServiceAccessException Error accessing the Descriptors Store
	*/
	//----------------------------------------
    public void revokePermissions(Uri uri)
        throws ServiceAccessException {
        if (permissions != null) 
			permissions.removeAllElements();
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Store an object permissions in the Descriptors Store.
	*
	* @param permission Permission we want to create
	* @exception ServiceAccessException Error accessing the Descriptors Store
	*/
	//----------------------------------------
    public Enumeration enumeratePermissions()
        throws ServiceAccessException {
        if (permissions == null) permissions = new Vector();
        return permissions.elements();
    }
    
    
	//----------------------------------------
	/**
	* Puts a lock on a subject.
	*
	* @param lock Lock token
	* @exception ServiceAccessException Service access error
	*/
	//----------------------------------------
    public void putLock(Uri uri, NodeLock lock)
        throws ServiceAccessException {
        if (locks == null) locks = new Vector();
        locks.addElement(lock.cloneObject());
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Renews a lock.
	*
	* @param lock Token to renew
	* @exception ServiceAccessException Service access error
	* @exception LockTokenNotFoundException Lock token was not found
	*/
	//----------------------------------------
	 public void renewLock(Uri uri, NodeLock lock) throws ServiceAccessException, LockTokenNotFoundException {
        if (locks == null) locks = new Vector();
		 boolean wasPresent = locks.removeElement(lock);
		 if (!wasPresent) {
			 throw new LockTokenNotFoundException(lock);
		 }
		 locks.addElement(lock.cloneObject());
		save(uri);
	 }

    
	//----------------------------------------
	/**
	* Removes (cancels) a lock.
	*
	* @param lock Token to remove
	* @exception ServiceAccessException Service access error
	* @exception LockTokenNotFoundException Lock token was not found
	*/
	//----------------------------------------
    public void removeLock(Uri uri,NodeLock lock)
        throws ServiceAccessException, LockTokenNotFoundException {
		
		if (locks == null) {
			throw new LockTokenNotFoundException(lock);
		}
		boolean wasPresent = locks.removeElement(lock);
		if (!wasPresent) {
			throw new LockTokenNotFoundException(lock);
		}
		save(uri);
	}
    
	//----------------------------------------
	/**
	* Returns the list of locks put on a subject.
	*
	* @param subject Subject
	* @return Enumeration List of locks which have been put on the subject
	* @exception ServiceAccessException Service access error
	*/
	//----------------------------------------
	public Enumeration enumerateLocks()
        throws ServiceAccessException {
        if (locks == null) locks = new Vector();
        return locks.elements();
    }
    
    
	//----------------------------------------
	/**
	* Retrieve a revision descriptors.
	*
	* @param uri Uri
	* @exception ServiceAccessException Service access error
	* @exception RevisionDescriptorNotFoundException Revision descriptor
	* was not found
	*/
	//----------------------------------------
	public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri)
		throws ServiceAccessException, RevisionDescriptorNotFoundException {
		if (revisionDescriptors == null) {
			throw new RevisionDescriptorNotFoundException(uri.toString());
		}
		return revisionDescriptors.cloneObject();
	}
	
    
	//----------------------------------------
	/**
	* Create new revision descriptors.
	*
	* @param uri Uri
	* @param revisionDescriptors Node revision descriptors
	* @exception ServiceAccessException Service access error
	*/
	//----------------------------------------
	public void createRevisionDescriptors (Uri uri,NodeRevisionDescriptors aRevisionDescriptors)
        throws ServiceAccessException {
        revisionDescriptors = aRevisionDescriptors.cloneObject();
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Update revision descriptors.
	*
	* @param uri Uri
	* @param revisionDescriptors Node revision descriptors
	* @exception ServiceAccessException Service access error
	* @exception RevisionDescriptorNotFoundException Revision descriptor
	* was not found
	*/
	//----------------------------------------
	public void storeRevisionDescriptors(Uri uri, NodeRevisionDescriptors aRevisionDescriptors)
        throws ServiceAccessException, RevisionDescriptorNotFoundException {
        if (!revisionDescriptors.getUri().equals(uri.toString())) {
            throw new RevisionDescriptorNotFoundException(uri.toString());
        }
        revisionDescriptors = aRevisionDescriptors.cloneObject();
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Remove revision descriptors.
	*
	* @param uri Uri
	* @exception ServiceAccessException Service access error
	*/
	//----------------------------------------
	public void removeRevisionDescriptors(Uri uri)
        throws ServiceAccessException {
        revisionDescriptors = null;
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Retrieve revision descriptor.
	*
	* @param Uri uri
	* @param revisionNumber Node revision number
	*/
	//----------------------------------------
	public NodeRevisionDescriptor retrieveRevisionDescriptor(Uri uri, NodeRevisionNumber revisionNumber)
        throws ServiceAccessException, RevisionDescriptorNotFoundException {
        Object result = null;
		
		if (descriptor!=null && revisionNumber!=null) result = descriptor.get(revisionNumber.toString());
			
        if (result == null) {
            throw new RevisionDescriptorNotFoundException(uri.toString());
        }
        return ((NodeRevisionDescriptor) result).cloneObject();
    }
    
    
	//----------------------------------------
	/**
	* Create new revision descriptor.
	*
	* @param uri Uri
	* @param revisionDescriptor Node revision descriptor
	* @exception ServiceAccessException Service access error
	*/
	//----------------------------------------
	public void createRevisionDescriptor(Uri uri, NodeRevisionDescriptor aRevisionDescriptor)
        throws ServiceAccessException {
		if (descriptor==null) descriptor=new Hashtable();

        descriptor.put(aRevisionDescriptor.getRevisionNumber().toString(),
                       aRevisionDescriptor.cloneObject());
		save(uri);
    }
    
    
	//----------------------------------------
	/**
	* Update revision descriptor.
	*
	* @param uri Uri
	* @param revisionDescriptors Node revision descriptor
	* @exception ServiceAccessException Service access error
	* @exception RevisionDescriptorNotFoundException Revision descriptor
	* was not found
	*/
	//----------------------------------------
	public void storeRevisionDescriptor(Uri uri, NodeRevisionDescriptor aRevisionDescriptor)
        throws ServiceAccessException, RevisionDescriptorNotFoundException {
        String key = aRevisionDescriptor.getRevisionNumber().toString();
        if (descriptor==null || !descriptor.containsKey(key)) {
            throw new RevisionDescriptorNotFoundException(uri.toString());
        }
        descriptor.put(key, aRevisionDescriptor.cloneObject());
		save(uri);
    }
    
	
	//----------------------------------------
	/**
	* Remove revision descriptor.
	*
	* @param uri Uri
	* @param revisionNumber Revision number
	* @exception ServiceAccessException Service access error
	*/
	//----------------------------------------
	public void removeRevisionDescriptor(Uri uri, NodeRevisionNumber number)
        throws ServiceAccessException {
		if (descriptor==null) return;
		
        descriptor.remove(number.toString());
		save(uri);
    }
	
}

/*
 * $Header$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 *
 * 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 [EMAIL PROTECTED]
 *
 * 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 slidestore.file;

//----------------------------------------
import java.io.*;
import java.util.*;
import java.lang.reflect.Constructor;
import java.text.SimpleDateFormat;
import org.apache.slide.common.*;
import org.apache.slide.store.*;
import org.apache.slide.structure.*;
import org.apache.slide.security.*;
import org.apache.slide.lock.*;
import org.apache.slide.content.*;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.output.XMLOutputter;
import org.jdom.input.SAXBuilder;
//----------------------------------------
/**
 * Handles the saving and retreiving of descriptions attached to an Uri</a>
 * @author <a href="mailto:[EMAIL PROTECTED]";>Marc D�cugis</a>
 * @contact <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a> 
 * @version $Revision$ , $Date$
 */

//----------------------------------------
//----------------------------------------
//----------------------------------------

//----------------------------------------
public class UriProperties extends AbstractUriProperties {
	/** A simple date format.*/
	protected SimpleDateFormat dateFormat;
	
	//----------------------------------------
	public UriProperties(String aRootPath,Uri aUri) throws ServiceAccessException {
		super(aRootPath,aUri);
		dateFormat=new SimpleDateFormat();
		File aFile=getFile(aUri);
		if (aFile.exists()) {
			init(aFile);
		}
	}
	// --------------------------------------
    public static File getFile(String aRootPath,Uri aUri) {
		System.out.println("----------- UriProperties getFile 1/n aUri="+aUri);
        // String aRelative = aUri.getRelative();
		// System.out.println("----------- UriProperties getFile 2/n aRelative="+aRelative);
       //  if (aRelative.equals("")) aRelative = "/";
		// System.out.println("----------- UriProperties getFile 3/n aRelative="+aRelative);

		// File aFile = new File(rootpath + aRelative + ".def.xml");
		File aFile = new File(aRootPath + aUri + ".def.xml");
		File aParentFile = new File(aFile.getParent());
		if ((aParentFile != null) && (!aParentFile.exists())) {
			aParentFile.mkdirs();
		}
		return aFile;
	}
	// --------------------------------------
    public File getFile(Uri aUri) {
		return getFile(rootpath,aUri);
	}
	// --------------------------------------
	public static XMLOutputter getXMLOutputter() {
		XMLOutputter aOutputter = new XMLOutputter();
		aOutputter.setEncoding("ISO-8859-1");//Unicode
		aOutputter.setNewlines(true);
		aOutputter.setIndent(true);
		aOutputter.setLineSeparator("\n");
		//aOutputter.setTextNormalize(true);


		return aOutputter;
	}
	// --------------------------------------
	public static String booleanToString(boolean aBoolean) {
		return aBoolean ? "true" : "false";
	}
	//----------------------------------------
	//----------------------------------------
	//----------------------------------------
	
	//----------------------------------------
	protected void save(Uri aUri) throws ServiceAccessException {
		try {
			File aFile=getFile(aUri);
			System.out.println("--------- save 1/n aFile="+aFile);
			Element aRoot=encode();
			System.out.println("--------- save 2/n");
			Document aDocument=new Document(aRoot);
			System.out.println("--------- save 3/n");
			OutputStream aOut=new FileOutputStream(aFile);
			XMLOutputter aOutputter = getXMLOutputter();
			// aOutputter.output(aDocument, System.out);
			aOutputter.output(aDocument, aOut);
			// if (DEBUG) trace("--------- enregistre 3/n");
			System.out.println("--------- save 4/n");
			aOut.flush();
			aOut.close();
			System.out.println("--------- save 5/n");
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new ServiceAccessException(null,e);
		}
	}
	//----------------------------------------
	protected Element encode() throws ServiceAccessException {
		Element aRoot=new Element("data");
		aRoot.addContent(encodeObject());
		aRoot.addContent(encodePermissions());
		aRoot.addContent(encodeLocks());
		aRoot.addContent(encodeRevisionDescriptors());
		aRoot.addContent(encodeRevisionDescriptor());
		return aRoot;
	}
	// --------------------------------------
	public Element encodeObject() {
		Element aElementObjectNode=new Element("objectnode");
		aElementObjectNode.setAttribute("classname",object.getClass().getName());
		aElementObjectNode.setAttribute("uri",object.getUri());
		aElementObjectNode.addContent(createElements("childs","child",object.enumerateChildren()));
		aElementObjectNode.addContent(createElements("links","link",object.enumerateLinks()));
		if (object instanceof LinkNode) {
			aElementObjectNode.setAttribute("linkTo",((LinkNode)object).getLinkedUri());
		}
		return aElementObjectNode;
	}
	// --------------------------------------
	public Element encodePermissions() {
		Element aPermissions=new Element("permissions");
		if (permissions==null) return aPermissions;
		
		for (int aSize=permissions.size(),i=0;i<aSize;i++) {
			NodePermission aPermission=(NodePermission)permissions.elementAt(i);
			aPermissions.addContent(encodeNodePermission(aPermission));
		}
		return aPermissions;
	}
	// --------------------------------------
	public Element encodeNodePermission(NodePermission aPermission) {
		Element aElementPermission=new Element("permission");
		NodeRevisionNumber aRevisionNumber=aPermission.getRevisionNumber();
		if (aRevisionNumber!=null) {
			aElementPermission.setAttribute("revisionNumber",encodeRevisionNumber(aRevisionNumber));
		}
		aElementPermission.setAttribute("subjectUri",aPermission.getSubjectUri());
		aElementPermission.setAttribute("actionUri",aPermission.getActionUri());
		aElementPermission.setAttribute("inheritable",booleanToString(aPermission.isInheritable()));
		aElementPermission.setAttribute("negative",booleanToString(aPermission.isNegative()));
		return aElementPermission;
    }
	// --------------------------------------
	public Element encodeLocks() {
		Element aElementLocks=new Element("locks");
		if (locks==null) return aElementLocks;
		
		for (int aSize=locks.size(),i=0;i<aSize;i++) {
			NodeLock aLock=(NodeLock)locks.elementAt(i);
			Element aElementLock=new Element("lock");
			aElementLock.setAttribute("subjectUri",aLock.getSubjectUri());
			aElementLock.setAttribute("typeUri",aLock.getTypeUri());
			aElementLock.setAttribute("date",dateFormat.format(aLock.getExpirationDate()));
			aElementLock.setAttribute("inheritance",booleanToString(aLock.isInheritable()));
			aElementLock.setAttribute("exclusive",booleanToString(aLock.isExclusive()));
			aElementLock.setAttribute("lockId",aLock.getLockId());
			aElementLocks.addContent(aElementLock);
		}
		return aElementLocks;
	}
	// --------------------------------------
	public Element encodeRevisionDescriptors() {
		
		Element aRevisionsHistory=new Element("revisionsHistory");
		if (revisionDescriptors==null) return aRevisionsHistory;

		aRevisionsHistory.setAttribute("initialRevision",encodeRevisionNumber(revisionDescriptors.getInitialRevision()));
		aRevisionsHistory.setAttribute("useVersioning",booleanToString(revisionDescriptors.hasRevisions()));
		
		System.out.println("---------- encodeRevisionDescriptors getLatestRevision="+
			revisionDescriptors.getLatestRevision());
		
		Element aBranchesElement=new Element("branches");
		Enumeration aBranches=revisionDescriptors.enumerateBranchNames();
		while (aBranches.hasMoreElements()) {
			String aBranchName=(String)aBranches.nextElement();
			Element aElementBranch=new Element("branch");
			aElementBranch.setAttribute("name",aBranchName);
			NodeRevisionNumber aRevisionNumber=revisionDescriptors.getLatestRevision(aBranchName);
			aElementBranch.setAttribute("lastestRevision",encodeRevisionNumber(aRevisionNumber));
			aBranchesElement.addContent(aElementBranch);
		}
		aRevisionsHistory.addContent(aBranchesElement);
		
		Element aRevisionsElement=new Element("revisions");
		Enumeration aRevisions=revisionDescriptors.enumerateRevisionNumbers();
		while (aRevisions.hasMoreElements()) {
			NodeRevisionNumber aRevisionNumber=(NodeRevisionNumber)aRevisions.nextElement();
			Element aRevisionElement=new Element("branch");
			aRevisionElement.setAttribute("start",encodeRevisionNumber(aRevisionNumber));
			
			Enumeration aSuccessors=revisionDescriptors.getSuccessors(aRevisionNumber);
			while (aSuccessors.hasMoreElements()) {
				NodeRevisionNumber aSuccessorRevisionNumber=(NodeRevisionNumber)aRevisions.nextElement();
				Element aSuccessorRevisionElement=new Element("revision");
				aSuccessorRevisionElement.setAttribute("number",encodeRevisionNumber(aSuccessorRevisionNumber));
				aRevisionElement.addContent(aSuccessorRevisionElement);
			}
			aRevisionsElement.addContent(aRevisionElement);
		}
		aRevisionsHistory.addContent(aRevisionsElement);
		
		return aRevisionsHistory;
	}
	// --------------------------------------
	public Element encodeRevisionDescriptor() {
		Element aRet=new Element("descriptor");
		if (descriptor==null) return aRet;

		for (Enumeration aEnum=descriptor.elements();aEnum.hasMoreElements();) {
			NodeRevisionDescriptor aRevisionDescriptor=(NodeRevisionDescriptor)aEnum.nextElement();
			aRet.addContent(encodeRevisionDescriptor(aRevisionDescriptor));
		}
		return aRet;
	}
	// --------------------------------------
	public Element encodeRevisionDescriptor(NodeRevisionDescriptor aDescriptor) {
		Element aRevisions=new Element("revisions");
		aRevisions.setAttribute("branchName",aDescriptor.getBranchName());
		aRevisions.setAttribute("number",encodeRevisionNumber(aDescriptor.getRevisionNumber()));
		aRevisions.addContent(createElements("labels","label",aDescriptor.enumerateLabels()));
		Element aProperties=new Element("properties");		
		
		for (Enumeration aEnum=aDescriptor.enumerateProperties();aEnum.hasMoreElements();) {
			Object aObject=aEnum.nextElement();
			System.out.println("---------- encodeRevisionDescriptor aObject="+aObject+" "+aObject.getClass().getName());
			NodeProperty aProp=(NodeProperty)aObject;
			aProperties.addContent(encodeNodeProperty(aProp));
		}
		aRevisions.addContent(aProperties);
		return aRevisions;
	}
	// --------------------------------------
	public String encodeRevisionNumber(NodeRevisionNumber aRevisionNumber) {
		return aRevisionNumber.getMajor()+"."+aRevisionNumber.getMinor();
	}
	// --------------------------------------
	public Element encodeNodeProperty(NodeProperty aProp) {
		Element aElement=new Element("property");
		aElement.setAttribute("name",aProp.getName());
		aElement.setAttribute("namespace",aProp.getNamespace());
		aElement.setAttribute("value",aProp.getValue().toString());
		aElement.setAttribute("type",aProp.getType());
		aElement.setAttribute("protected",booleanToString(aProp.isProtected()));
		Element aPermissions=new Element("permissions");
		
		for (Enumeration aEnum=aProp.enumeratePermissions();aEnum.hasMoreElements();) {
			NodePermission aPermission=(NodePermission)aEnum.nextElement();
			aPermissions.addContent(encodeNodePermission(aPermission));
		}
		aElement.addContent(aPermissions);
		return aElement;
	}
	// --------------------------------------
	public Element createElements(String aParent,String aChild,Enumeration aEnum) {
		Element aElement=new Element(aParent);
		while (aEnum.hasMoreElements()) {
			Object aObject=aEnum.nextElement();
			Element aItem=new Element(aChild);
			aItem.setAttribute("val",aObject.toString());
			aElement.addContent(aItem);
		}
		return aElement;
	}
	//----------------------------------------
	//----------------------------------------
	//----------------------------------------
	
	//----------------------------------------
	protected void init(File aFile) throws ServiceAccessException {
		try {
			System.out.println("--------- init 1/n aFile="+aFile);
			SAXBuilder aBuilder=new SAXBuilder();
			FileInputStream aIn=new FileInputStream(aFile);
			Document aDocument=aBuilder.build(aIn);
			System.out.println("--------- init 2/n");
			decode(aDocument.getRootElement());
			System.out.println("--------- init 3/n");
			aIn.close();
			System.out.println("--------- init 5/n");
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new ServiceAccessException(null,e);
		}
	}
	//----------------------------------------
	protected void decode(Element aRoot) throws ServiceAccessException {
		decodeObject(aRoot);
		decodePermissions(aRoot);
		decodeLocks(aRoot);
		decodeRevisionDescriptors(aRoot);
		decodeRevisionDescriptor(aRoot);
	}
	// --------------------------------------
	public void decodeObject(Element aElement) throws ServiceAccessException {
		try {
			Element aElementObjectNode=aElement.getChild("objectnode");
			String aClasseName=aElementObjectNode.getAttributeValue("classname");
			String aUri=aElementObjectNode.getAttributeValue("uri");
			Vector aChilds=createVector(aElementObjectNode,"childs","child");
			Vector aLinks=createVector(aElementObjectNode,"links","link");
			System.out.println("--------- decodeObject  aChilds="+aChilds);
			System.out.println("--------- decodeObject  aLinks="+aLinks);
			Class aTypes[] = null;
			Object aArgs[] = null;

			if (aClasseName.equals(LinkNode.class.getName())) {
				String aLinkTo=aElementObjectNode.getAttributeValue("linkTo");
				aTypes= new Class[]{String.class,Vector.class,Vector.class,String.class};
				aArgs= new Object[]{aUri, aChilds, aLinks,aLinkTo};
			}
			else {
				aTypes=new Class[] {String.class,Vector.class,Vector.class};
				aArgs=new Object[] {aUri, aChilds, aLinks};
			}
			object=(ObjectNode) createObject(aClasseName,aTypes,aArgs);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new ServiceAccessException(null,e);
		}
	}
	
	// --------------------------------------
	public void decodePermissions(Element aElement) {
		permissions=new Vector();
		String aUri=object.getUri().toString();
		Element aPermissions=aElement.getChild("permissions");
		List aList=aPermissions.getChildren();
		for (int i=0;i<aList.size();i++) {
			Element aChild=(Element)aList.get(i);
			permissions.addElement(decodePermission(aChild,aUri));
		}
	}
	// --------------------------------------
	public void decodeLocks(Element aElement) throws ServiceAccessException {
		try {
			locks=new Vector();
			Element aElementLocks=aElement.getChild("locks");
			List aList=aElementLocks.getChildren();
			
			for (int i=0;i<aList.size();i++) {
				Element aChild=(Element)aList.get(i);
				String aSubject=aChild.getAttributeValue("subjectUri");
				String aType=aChild.getAttributeValue("typeUri");
				Date aDateExpiration=dateFormat.parse(aChild.getAttributeValue("date"));
				boolean aInheritable=Boolean.getBoolean(aChild.getAttributeValue("inheritance"));
				boolean aNegative=Boolean.getBoolean(aChild.getAttributeValue("exclusive"));
				String aLockId=aChild.getAttributeValue("lockId");
				locks.addElement(
					new NodeLock(aLockId,object.getUri(),aSubject,aType,aDateExpiration,aInheritable,aNegative)
				);
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new ServiceAccessException(null,e);
		}
		
	}
	// --------------------------------------
	public void decodeRevisionDescriptors(Element aElement) {
		Element aRevisionsHistory=aElement.getChild("revisionsHistory");

		NodeRevisionNumber aInitialRevision=decodeRevisionNumber(aRevisionsHistory.getAttributeValue("initialRevision"));
		boolean aUseVersionning=Boolean.getBoolean(aRevisionsHistory.getAttributeValue("useVersioning"));

		Element aBranchesElement=aElement.getChild("branches");
		if (aBranchesElement==null) {
			revisionDescriptors=new NodeRevisionDescriptors(
				object.getUri().toString(),aInitialRevision,new Hashtable(),new Hashtable(),new Hashtable(),aUseVersionning);			
				return; 
		}
		
		List aList=aBranchesElement.getChildren();
		Hashtable aLastestRevisions=new Hashtable();
		for (int i=0;i<aList.size();i++) {
			Element aChild=(Element)aList.get(i);
			String aName=aChild.getAttributeValue("name");
			NodeRevisionNumber aRevisionNumber=decodeRevisionNumber(aChild.getAttributeValue("lastestRevision"));
			aLastestRevisions.put(aName,aRevisionNumber);
		}
		Hashtable aBranches=new Hashtable();
		Element aRevisionsElement=aElement.getChild("revisions");
		aList=aRevisionsElement.getChildren();
		for (int i=0;i<aList.size();i++) {
			Element aChild=(Element)aList.get(i);
			NodeRevisionNumber aStartNumber=decodeRevisionNumber(aChild.getAttributeValue("start"));
			List aSuccessors=aChild.getChildren();
			Vector aSuccessorsNumbers=new Vector();
			for (int k=0;k<aSuccessors.size();k++) {
				Element aSuccessor=(Element)aSuccessors.get(i);
				NodeRevisionNumber aRevisionNumber=decodeRevisionNumber(aChild.getAttributeValue("number"));
				aSuccessorsNumbers.addElement(aRevisionNumber);
			}
			aBranches.put(aStartNumber,aSuccessorsNumbers);
		}
		revisionDescriptors=new NodeRevisionDescriptors(
				object.getUri().toString(),aInitialRevision,new Hashtable(),aLastestRevisions,aBranches,aUseVersionning);
	}
	// --------------------------------------
	public void decodeRevisionDescriptor(Element aParent) {
		descriptor=new Hashtable();
		
		Element aElement=aParent.getChild("descriptor");
		if (aElement==null) return;
		
		List aList=aElement.getChildren();
		String aUri=object.getUri().toString();
		
		for (int i=0;i<aList.size();i++) {
			Element aChild=(Element)aList.get(i);
			String aBranchName=aChild.getAttributeValue("branchName");
			NodeRevisionNumber aRevisionNumber=decodeRevisionNumber(aChild.getAttributeValue("number"));

			Vector aLabels=new Vector();
			Element aLabelsElement=(Element)aChild.getChild("labels");
			List aLabelList=aLabelsElement.getChildren();
			for (int k=0;k<aLabelList.size();k++) {
				Element aLabel=(Element)aLabelList.get(i);
				aLabels.addElement(aLabel.getAttributeValue("val"));
			}

			Hashtable aProperties=new Hashtable();
			Element aPropertiesElement=(Element)aChild.getChild("properties");
			List aPropertiesList=aPropertiesElement.getChildren();
			for (int k=0;k<aPropertiesList.size();k++) {
				Element aPropertie=(Element)aPropertiesList.get(i);
				NodeProperty aProp=decodeNodeProperty(aPropertie,aUri);
				aProperties.put(aPropertie.getNamespace() + aPropertie.getName(),aProp);
			}
			NodeRevisionDescriptor aNode=new NodeRevisionDescriptor(aRevisionNumber,aBranchName,aLabels,aProperties);
			descriptor.put(aRevisionNumber,aNode);
		}		
	}
	// --------------------------------------
	public NodePermission decodePermission(Element aElement,String aUri) {
		String aRevisionNumber=aElement.getAttributeValue("revisionNumber");
		String aSubject=aElement.getAttributeValue("subjectUri");
		String aAction=aElement.getAttributeValue("actionUri");
		boolean aInheritable=Boolean.getBoolean(aElement.getAttributeValue("inheritable"));
		boolean aNegative=Boolean.getBoolean(aElement.getAttributeValue("negative"));
		return new NodePermission(aUri,aRevisionNumber,aSubject,aAction,aInheritable,aNegative);

	}
	// --------------------------------------
	public NodeRevisionNumber decodeRevisionNumber(Element aElement) {
		Element aElementRevision=aElement.getChild("revision");
		return new NodeRevisionNumber(Integer.parseInt(aElementRevision.getAttributeValue("major")),
									  Integer.parseInt(aElementRevision.getAttributeValue("minor")));
	}
	// --------------------------------------
	public NodeRevisionNumber decodeRevisionNumber(String aStr) {
		return (aStr==null ? null : new NodeRevisionNumber(aStr));
	}
	// --------------------------------------
	public NodeProperty decodeNodeProperty(Element aElement,String aUri) {
		String aName=aElement.getAttributeValue("name");
		String aValue=aElement.getAttributeValue("value");
		String aNamespace=aElement.getAttributeValue("namespace");
		String aType=aElement.getAttributeValue("type");
		boolean aProtected=Boolean.getBoolean(aElement.getAttributeValue("protected"));
		
		Element aPermisionsElement=aElement.getChild("permissions");
		List aList=aPermisionsElement.getChildren();
		Vector aPermission=new Vector();
		for (int i=0;i<aList.size();i++) {
			Element aChild=(Element)aList.get(i);
			aPermission.addElement(decodePermission(aChild,aUri));
		}
		return new NodeProperty(aName,aValue,aNamespace,aType,aProtected);
	}

	// --------------------------------------
	public Vector createVector(Element aElement,String aParentName,String aChildName) {
		Element aParent=aElement.getChild(aParentName);
		Vector aRet=new Vector();
		System.out.println("--------- createVector  aParentName="+aParentName+" aChildName="+aChildName);
		List aList=aParent.getChildren(aChildName);
		System.out.println("--------- createVector  aList="+aList);
		for (int i=0;i<aList.size();i++) {
			Element aChild=(Element)aList.get(i);
			aRet.addElement(aChild.getAttributeValue("val"));
		}
		return aRet;
	}
	// --------------------------------------
	public Object createObject(String aNomClasse,Class aTypes[],Object aArgs[]) throws UnknownObjectClassException {
		Class aClasse = null;
		try {
			// First, load the object's class
			aClasse = Class.forName(aNomClasse);
			Constructor aConstructor = aClasse.getConstructor(aTypes);
			if (aConstructor==null) aConstructor=aClasse.getSuperclass().getConstructor(aTypes);
			return aConstructor.newInstance(aArgs);
			
		}
		catch (Exception e) {
			throw new UnknownObjectClassException(aNomClasse);
		}
	}
	/*
	// --------------------------------------
	public Vector decodeObject(Vector aVector,Enumeration aEnum) {
	}
	*/
}
/*
 * $Header$
 * $Revision$
 * $Date$
 *
 * ====================================================================
 *
 * 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 [EMAIL PROTECTED]
 *
 * 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 slidestore.file;

import java.util.Hashtable;
import java.util.Enumeration;
import java.util.Vector;
import java.io.File;
import org.apache.slide.common.*;
import org.apache.slide.store.*;
import org.apache.slide.structure.*;
import org.apache.slide.security.*;
import org.apache.slide.lock.*;
import org.apache.slide.content.*;

/**
 * Memory with persistence, reorganization of the <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a>
 * Reference implementation.
 * Use of UriProperties.
 * @author <a href="mailto:[EMAIL PROTECTED]";>Marc D�cugis</a>
 * @contact <a href="mailto:[EMAIL PROTECTED]";>Remy Maucherat</a> 
 * @version $Revision$ , $Date$
 */
public class XMLMemDescriptorsStore extends AbstractService
    implements LockStore, NodeStore, RevisionDescriptorsStore,
    RevisionDescriptorStore, SecurityStore {
    
    
    // ----------------------------------------------------- Instance Variables
    
    
    /** Caches all the uri's definition */
    protected Hashtable definitions;

    /**
     * Path from which files are stored.
     */
    protected String rootpath;
	
	/**Return de uri properties associated with uri
	* @return null if the uri has no properties
	*/
	protected UriProperties getUriProperties(Uri uri) {
		return (UriProperties)definitions.get(uri.toString());
	}
    
    // ---------------------------------------------------- ServiceImpl Methods
    
    
    /**
     * Initializes the descriptors store with a set of parameters.
     * Those could be :
     * <li>User name, login info
     * <li>Host name on which to connect
     * <li>Remote port
     * <li>JDBC driver whoich is to be used :-)
     * <li>Anything else ...
     *
     * @param parameters Hashtable containing the parameters' name
     * and associated value
     */
    public void setParameters(Hashtable parameters)
        throws ServiceParameterErrorException,
        ServiceParameterMissingException {
		// copy/paste of FileDescriptorsStoreNoVersioning
		
		
        // A parameter will tell were serialization files are.
        rootpath = (String) parameters.get("rootpath");
        if (rootpath == null) {
            // Default is that files are stored starting in the 
            // current directory
            rootpath = "";
        }
		System.out.println("----------- XMLMemDescriptorsStore setParameters rootpath="+rootpath);
    }
    
    
    /**
     * Connects to descriptors store.
     *
     * @exception DataException
     */
    public synchronized void connect()
        throws ServiceConnectionFailedException {
		System.out.println("----------- XMLMemDescriptorsStore connect definitions="+definitions);
        if (definitions == null) {
            definitions = new Hashtable();
        }
    }
    
    
    /**
     * Disconnects from descriptors store.
     *
     * @exception ServiceDisconnectionFailedException
     */
    public void disconnect()
        throws ServiceDisconnectionFailedException {
    }
    
    
    /**
     * Initializes descriptors store.
     *
     * @exception ServiceInitializationFailedException Throws an exception
     * if the descriptors store has already been initialized before
     */
    public synchronized void initialize(NamespaceAccessToken token)
        throws ServiceInitializationFailedException {
        super.initialize(token);
		System.out.println("----------- XMLMemDescriptorsStore initialize token="+token);
		definitions = new Hashtable();
    }
    
    
    /**
     * Deletes descriptors store. Should remove stored data if possible.
     *
     * @exception ServiceResetFailedException Reset failed
     */
    public synchronized void reset()
        throws ServiceResetFailedException {
		
		definitions = new Hashtable();
    }
    
    
    /**
     * Does nothing.
     *
     * @exception ServiceAccessException Service access error
     */
    public void commit()
        throws ServiceAccessException {
    }
    
    
    /**
     * This function tells whether or not the descriptors store is connected.
     *
     * @return boolean true if we are connected
     * @exception ServiceAccessException Service access error
     */
    public boolean isConnected()
        throws ServiceAccessException {
        return true;
    }
    
    
    
    // ----------------------------------------------- DescriptorsStore Methods
    
    
    /**
     * Retrive an object from the Descriptors Store.
     *
     * @param uri Uri of the object we want to retrieve
     * @exception ServiceAccessException Error accessing the Descriptors Store
     * @exception ObjectNotFoundException The object to retrieve was not found
     */
    public ObjectNode retrieveObject(Uri uri)
        throws ServiceAccessException, ObjectNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore retrieveObject uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			File aFile=UriProperties.getFile(rootpath,uri);
			if (aFile.exists()) {
				try {
					aProps=new UriProperties(rootpath,uri);
				}
				catch (ServiceAccessException e) {
					throw new ObjectNotFoundException(uri);
				}
				definitions.put(uri.toString(),aProps);
			}
			else {
				throw new ObjectNotFoundException(uri);
			}
        }
        return aProps.retrieveObject(uri);
    }
    
    
    /**
     * Store an object in the Descriptors Store.
     *
     * @param object Object to update
     * @exception ServiceAccessException Error accessing the Descriptors Store
     * @exception ObjectNotFoundException The object to update was not found
     */
    public void storeObject(Uri uri, ObjectNode object)
        throws ServiceAccessException, ObjectNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		try {
			if (aProps == null) {
				aProps=new UriProperties(rootpath,uri);
				definitions.put(uri.toString(),aProps);
			}
		}
		catch (Throwable t) {
			t.printStackTrace();
		}
		aProps.storeObject(uri,object);
		System.out.println("----------- XMLMemDescriptorsStore storeObject 3/n uri="+uri+" aProps="+aProps);

    }
    
    
    /**
     * Create a new object in the Descriptors Store.
     *
     * @param object SlideObject
     * @param uri Uri of the object we want to create
     * @exception ServiceAccessException Error accessing the Descriptors Store
     * @exception ObjectAlreadyExistsException An object already exists
     * at this Uri
     */
    public void createObject(Uri uri, ObjectNode object)
        throws ServiceAccessException, ObjectAlreadyExistsException {
        try {
			UriProperties aProps = getUriProperties(uri);
			System.out.println("----------- XMLMemDescriptorsStore 1/n createObject uri="+uri+" aProps="+aProps);
			if (aProps == null) {
				storeObject(uri,object);
            }
			else {
				aProps.createObject(uri, object);
			}
        } catch(ObjectNotFoundException e) {
            // Never happens
        }
    }
    
    
    /**
     * Remove an object from the Descriptors Store.
     *
     * @param object Object to remove
     * @exception ServiceAccessException Error accessing the Descriptors Store
     * @exception ObjectNotFoundException The object to remove was not found
     */
    public void removeObject(Uri uri, ObjectNode object)
        throws ServiceAccessException, ObjectNotFoundException {
		UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore removeObject 1/n uri="+uri+" aProps="+aProps);
		if (aProps == null) {
            throw new ObjectNotFoundException(uri);
        }
        aProps.removeObject(uri,object);
		System.out.println("----------- XMLMemDescriptorsStore removeObject 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Store an object permissions in the Descriptors Store.
     *
     * @param permission Permission we want to create
     * @exception ServiceAccessException Error accessing the Descriptors Store
     */
    public void grantPermission(Uri uri, NodePermission permission)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore grantPermission 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			aProps=new UriProperties(rootpath,uri);
			definitions.put(uri.toString(),aProps);
        }
		aProps.grantPermission(uri,permission);
		System.out.println("----------- XMLMemDescriptorsStore grantPermission 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Store an object permissions in the Descriptors Store.
     *
     * @param permission Permission we want to create
     * @exception ServiceAccessException Error accessing the Descriptors Store
     */
    public void revokePermission(Uri uri, NodePermission permission)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore revokePermission 1/n uri="+uri+" aProps="+aProps);
        if (aProps != null) {
			aProps.revokePermission(uri,permission);
        }
		System.out.println("----------- XMLMemDescriptorsStore revokePermission 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Revoke all the permissions on the object .
     *
     * @param permission Permission we want to create
     * @exception ServiceAccessException Error accessing the Descriptors Store
     */
    public void revokePermissions(Uri uri)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore revokePermissions 1/n uri="+uri+" aProps="+aProps);
        if (aProps != null) {
			aProps.revokePermissions(uri);
        }
		System.out.println("----------- XMLMemDescriptorsStore revokePermissions 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Store an object permissions in the Descriptors Store.
     *
     * @param permission Permission we want to create
     * @exception ServiceAccessException Error accessing the Descriptors Store
     */
    public Enumeration enumeratePermissions(Uri uri)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore enumeratePermissions 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			return new Vector().elements();
        }
        else {
			return aProps.enumeratePermissions();
		}
    }
    
    
    /**
     * Puts a lock on a subject.
     *
     * @param lock Lock token
     * @exception ServiceAccessException Service access error
     */
    public void putLock(Uri uri, NodeLock lock)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore putLock 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			aProps=new UriProperties(rootpath,uri);
			definitions.put(uri.toString(),aProps);
        }
		aProps.putLock(uri,lock);
		System.out.println("----------- XMLMemDescriptorsStore putLock 2/n uri="+uri+" aProps="+aProps);
     }
    
    
    /**
     * Renews a lock.
     *
     * @param lock Token to renew
     * @exception ServiceAccessException Service access error
     * @exception LockTokenNotFoundException Lock token was not found
     */
    public void renewLock(Uri uri, NodeLock lock)
        throws ServiceAccessException, LockTokenNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore renewLock 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			aProps=new UriProperties(rootpath,uri);
			definitions.put(uri.toString(),aProps);
        }
		aProps.renewLock(uri,lock);
		System.out.println("----------- XMLMemDescriptorsStore renewLock 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Removes (cancels) a lock.
     *
     * @param lock Token to remove
     * @exception ServiceAccessException Service access error
     * @exception LockTokenNotFoundException Lock token was not found
     */
    public void removeLock(Uri uri, NodeLock lock)
        throws ServiceAccessException, LockTokenNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore removeLock 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
            throw new LockTokenNotFoundException(lock);
        } else {
			aProps.removeLock(uri,lock);
        }
		System.out.println("----------- XMLMemDescriptorsStore removeLock 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Kills a lock.
     *
     * @param lock Token to remove
     * @exception ServiceAccessException Service access error
     * @exception LockTokenNotFoundException Lock token was not found
     */
    public void killLock(Uri uri, NodeLock lock)
        throws ServiceAccessException, LockTokenNotFoundException {
        removeLock(uri, lock);
    }
    
    
    /**
     * Returns the list of locks put on a subject.
     *
     * @param subject Subject
     * @return Enumeration List of locks which have been put on the subject
     * @exception ServiceAccessException Service access error
     */
    public Enumeration enumerateLocks(Uri uri)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore enumerateLocks 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			return new Vector().elements();
        }
        else {
			return aProps.enumerateLocks();
		}
    }
    
    
    /**
     * Retrieve a revision descriptors.
     *
     * @param uri Uri
     * @exception ServiceAccessException Service access error
     * @exception RevisionDescriptorNotFoundException Revision descriptor
     * was not found
     */
    public NodeRevisionDescriptors retrieveRevisionDescriptors(Uri uri)
        throws ServiceAccessException, RevisionDescriptorNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore retrieveRevisionDescriptors 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
            throw new RevisionDescriptorNotFoundException(uri.toString());
        }
		System.out.println("----------- XMLMemDescriptorsStore retrieveRevisionDescriptors 2/n uri="+uri+" aProps="+aProps);
        return aProps.retrieveRevisionDescriptors(uri);
    }
    
    
    /**
     * Create new revision descriptors.
     *
     * @param uri Uri
     * @param revisionDescriptors Node revision descriptors
     * @exception ServiceAccessException Service access error
     */
    public void createRevisionDescriptors
        (Uri uri, NodeRevisionDescriptors revisionDescriptors)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore createRevisionDescriptors 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			aProps=new UriProperties(rootpath,uri);
			definitions.put(uri.toString(),aProps);
        }
		aProps.createRevisionDescriptors(uri,revisionDescriptors);
		System.out.println("----------- XMLMemDescriptorsStore createRevisionDescriptors 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Update revision descriptors.
     *
     * @param uri Uri
     * @param revisionDescriptors Node revision descriptors
     * @exception ServiceAccessException Service access error
     * @exception RevisionDescriptorNotFoundException Revision descriptor
     * was not found
     */
    public void storeRevisionDescriptors
        (Uri uri, NodeRevisionDescriptors revisionDescriptors)
        throws ServiceAccessException, RevisionDescriptorNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore storeRevisionDescriptors 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
            throw new RevisionDescriptorNotFoundException(uri.toString());
        }
        aProps.storeRevisionDescriptors(uri, revisionDescriptors);
		System.out.println("----------- XMLMemDescriptorsStore storeRevisionDescriptors 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Remove revision descriptors.
     *
     * @param uri Uri
     * @exception ServiceAccessException Service access error
     */
    public void removeRevisionDescriptors(Uri uri)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore removeRevisionDescriptors 1/n uri="+uri+" aProps="+aProps);
        if (aProps != null) {
			aProps.removeRevisionDescriptors(uri);
        }
		System.out.println("----------- XMLMemDescriptorsStore removeRevisionDescriptors 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Retrieve revision descriptor.
     *
     * @param Uri uri
     * @param revisionNumber Node revision number
     */
    public NodeRevisionDescriptor retrieveRevisionDescriptor (Uri uri, NodeRevisionNumber revisionNumber)
        throws ServiceAccessException, RevisionDescriptorNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore retrieveRevisionDescriptor 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			aProps=new UriProperties(rootpath,uri);
			definitions.put(uri.toString(),aProps);
        }
		System.out.println("----------- XMLMemDescriptorsStore retrieveRevisionDescriptor 2/n uri="+uri+" revisionNumber="+revisionNumber);
		try {
			return aProps.retrieveRevisionDescriptor(uri,revisionNumber);
		}
		catch (RevisionDescriptorNotFoundException e) {
			System.out.println("----------- XMLMemDescriptorsStore retrieveRevisionDescriptor 3/n uri="+uri+" aProps="+aProps);
			e.printStackTrace();
			throw e;
		}
    }
    
    
    /**
     * Create new revision descriptor.
     *
     * @param uri Uri
     * @param revisionDescriptor Node revision descriptor
     * @exception ServiceAccessException Service access error
     */
    public void createRevisionDescriptor
        (Uri uri, NodeRevisionDescriptor revisionDescriptor)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore createRevisionDescriptor 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
			aProps=new UriProperties(rootpath,uri);
			definitions.put(uri.toString(),aProps);
        }
		aProps.createRevisionDescriptor(uri,revisionDescriptor);
		System.out.println("----------- XMLMemDescriptorsStore createRevisionDescriptor 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Update revision descriptor.
     *
     * @param uri Uri
     * @param revisionDescriptors Node revision descriptor
     * @exception ServiceAccessException Service access error
     * @exception RevisionDescriptorNotFoundException Revision descriptor
     * was not found
     */
    public void storeRevisionDescriptor(Uri uri, NodeRevisionDescriptor revisionDescriptor)
        throws ServiceAccessException, RevisionDescriptorNotFoundException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore storeRevisionDescriptor 1/n uri="+uri+" aProps="+aProps);
        if (aProps == null) {
            throw new RevisionDescriptorNotFoundException(uri.toString());
        }
		aProps.storeRevisionDescriptor(uri,revisionDescriptor);
		System.out.println("----------- XMLMemDescriptorsStore storeRevisionDescriptor 2/n uri="+uri+" aProps="+aProps);
    }
    
    
    /**
     * Remove revision descriptor.
     *
     * @param uri Uri
     * @param revisionNumber Revision number
     * @exception ServiceAccessException Service access error
     */
    public void removeRevisionDescriptor(Uri uri, NodeRevisionNumber number)
        throws ServiceAccessException {
        UriProperties aProps = getUriProperties(uri);
		System.out.println("----------- XMLMemDescriptorsStore removeRevisionDescriptor 1/n uri="+uri+" aProps="+aProps);
        if (aProps != null) {
			aProps.removeRevisionDescriptor(uri,number);
        }
		System.out.println("----------- XMLMemDescriptorsStore removeRevisionDescriptor 2/n uri="+uri+" aProps="+aProps);
    }


    
}


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to