You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by pn...@apache.org on 2003/08/21 16:48:22 UTC

cvs commit: jakarta-slide/src/share/org/apache/slide/macro MacroParameters.java MacroImpl.java Macro.java

pnever      2003/08/21 07:48:22

  Modified:    src/share/org/apache/slide/macro MacroParameters.java
                        MacroImpl.java Macro.java
  Log:
  COPY and binding: fixed the "diamond" problem - i.e.
  "If a COPY request would cause a new resource to be created
  as a copy of an existing resource, and that COPY request
  has already created a copy of that existing resource,
  the COPY request instead creates another binding to the
  previous copy, instead of creating a new resource. "
  
  Revision  Changes    Path
  1.6       +33 -12    jakarta-slide/src/share/org/apache/slide/macro/MacroParameters.java
  
  Index: MacroParameters.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/MacroParameters.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MacroParameters.java	18 Aug 2003 06:49:20 -0000	1.5
  +++ MacroParameters.java	21 Aug 2003 14:48:22 -0000	1.6
  @@ -68,11 +68,16 @@
    *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    */
  +import java.util.HashMap;
  +import java.util.Map;
  +
   public class MacroParameters {
       
  -    private boolean recursive;
  -    private boolean overwrite;
  -    private boolean deleteCreate;
  +    private static final String RECURSIVE = "recursive";
  +    private static final String OVERWRITE = "overwrite";
  +    private static final String DELETE_CREATE = "deleteCreate";
  +    
  +    private Map parameters = new HashMap();
       
       /**
        * Constructor.
  @@ -101,9 +106,9 @@
        *
        */
       public MacroParameters(boolean recursive, boolean overwrite, boolean deleteCreate) {
  -        this.recursive = recursive;
  -        this.overwrite = overwrite;
  -        this.deleteCreate = (overwrite && deleteCreate);
  +        setBooleanParameter( RECURSIVE, recursive );
  +        setBooleanParameter( OVERWRITE, overwrite );
  +        setBooleanParameter( DELETE_CREATE, (overwrite && deleteCreate) );
       }
       
       /**
  @@ -112,7 +117,7 @@
        * @return boolean True if the macro is recursive
        */
       public boolean isRecursive() {
  -        return recursive;
  +        return getBooleanParameter( RECURSIVE );
       }
       
       /**
  @@ -122,7 +127,7 @@
        * destination (may not apply to all macros)
        */
       public boolean isOverwrite() {
  -        return overwrite;
  +        return getBooleanParameter( OVERWRITE );
       }
       
       /**
  @@ -133,6 +138,22 @@
        * resources at detination
        */
       public boolean isDeleteCreate() {
  -        return deleteCreate;
  +        return getBooleanParameter( DELETE_CREATE );
  +    }
  +    
  +    public void setParameter( String name, Object value ) {
  +        parameters.put( name, value );
  +    }
  +    
  +    public void setBooleanParameter( String name, boolean value ) {
  +        parameters.put( name, new Boolean(value) );
  +    }
  +    
  +    public Object getParameter( String name ) {
  +        return parameters.get( name );
  +    }
  +    
  +    public boolean getBooleanParameter( String name ) {
  +        return ((Boolean)parameters.get(name)).booleanValue();
       }
   }
  
  
  
  1.31      +77 -70    jakarta-slide/src/share/org/apache/slide/macro/MacroImpl.java
  
  Index: MacroImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/MacroImpl.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- MacroImpl.java	18 Aug 2003 06:49:20 -0000	1.30
  +++ MacroImpl.java	21 Aug 2003 14:48:22 -0000	1.31
  @@ -65,6 +65,9 @@
   
   import java.util.Arrays;
   import java.util.Enumeration;
  +import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.Map;
   import java.util.StringTokenizer;
   import org.apache.slide.common.Domain;
   import org.apache.slide.common.Namespace;
  @@ -72,6 +75,7 @@
   import org.apache.slide.common.ServiceAccessException;
   import org.apache.slide.common.SlideException;
   import org.apache.slide.common.SlideToken;
  +import org.apache.slide.common.SlideTokenWrapper;
   import org.apache.slide.content.Content;
   import org.apache.slide.content.NodeProperty;
   import org.apache.slide.content.NodeRevisionContent;
  @@ -102,9 +106,12 @@
    */
   public final class MacroImpl implements Macro {
       
  -    
  -    // ----------------------------------------------------------- Constructors
  -    
  +    private Namespace namespace;
  +    private NamespaceConfig namespaceConfig;
  +    private Content contentHelper;
  +    private Structure structureHelper;
  +    private Security securityHelper;
  +    private Lock lockHelper;
       
       /**
        * Constructor.
  @@ -126,49 +133,6 @@
           this.lockHelper      = lockHelper;
       }
       
  -    
  -    // ----------------------------------------------------- Instance Variables
  -    
  -    
  -    /**
  -     * Namespace.
  -     */
  -    private Namespace namespace;
  -    
  -    
  -    /**
  -     * Namespace configuration.
  -     */
  -    private NamespaceConfig namespaceConfig;
  -    
  -    
  -    /**
  -     * Content helper.
  -     */
  -    private Content contentHelper;
  -    
  -    
  -    /**
  -     * Structure helper.
  -     */
  -    private Structure structureHelper;
  -    
  -    
  -    /**
  -     * Security helper.
  -     */
  -    private Security securityHelper;
  -    
  -    
  -    /**
  -     * Lock helper.
  -     */
  -    private Lock lockHelper;
  -    
  -    
  -    // ---------------------------------------------------------- Macro Methods
  -    
  -    
       /**
        * Recursive copy with overwrite macro.
        *
  @@ -274,6 +238,14 @@
               throw e;
           }
           
  +        // try to writeLock the complete destination tree
  +        synchronized( this ) {
  +            try {
  +                writeLock(token, destinationUri, true);
  +            }
  +            catch (SlideException x) {}; // ignore silently
  +        }
  +        
           if (parameters.isDeleteCreate()) {
               try {
                   // We make sure the object we want to overwrite exists
  @@ -290,21 +262,9 @@
                   throw e;
               }
           }
  -        else {
  -            try {
  -                // TEMPORARY HACK !!!
  -                // "touch" the destination resource to "lock" it (whole tree in case
  -                // of destination being a collection) in the store.
  -                //
  -                // TODO: remove when Slide-Kernel becomes aware of binding, i.e.
  -                // performes the resolve URI -> Resource-ID itself.
  -                ObjectNode onode = structureHelper.retrieve(token, destinationUri);
  -                structureHelper.store(token, onode);
  -            }
  -            catch (SlideException x) {
  -                // ignore silently
  -            }
  -        }
  +        
  +        Map alreadyCopied = new HashMap(); // maps source-UURI -> destination-URI
  +        parameters.setParameter( ALREADY_COPIED, alreadyCopied );
           
           copyObject(token, sourceUri, destinationUri, parameters, e, copyRedirector, copyListener);
           
  @@ -315,6 +275,25 @@
           
       }
       
  +    /**
  +     * WriteLock the specified URI
  +     *
  +     * @param    token               a  SlideToken
  +     * @param    uri                 a  String
  +     * @param    recursive           a  boolean
  +     * @throws   SlideException
  +     */
  +    private void writeLock(SlideToken token, String uri, boolean recursive) throws SlideException {
  +        if (!token.isForceStoreEnlistment()) {
  +            token = new SlideTokenWrapper(token, true);
  +        }
  +        ObjectNode onode = structureHelper.retrieve(token, uri);
  +        if (onode != null && recursive) {
  +            Iterator i = onode.getChildren().iterator();
  +            writeLock( token, (String)i.next(), true );
  +        }
  +    }
  +    
       // TODO: copyRedirector not used
       public void rebind(SlideToken token, String sourceUri,
                          String destinationUri, MacroParameters parameters,
  @@ -331,6 +310,14 @@
               throw e;
           }
           
  +        // try to writeLock the complete destination tree
  +        synchronized( this ) {
  +            try {
  +                writeLock(token, destinationUri, true);
  +            }
  +            catch (SlideException x) {}; // ignore silently
  +        }
  +        
           if (parameters.isDeleteCreate()) {
               try {
                   // If the object we want to overwrite exists, we delete is first
  @@ -597,9 +584,9 @@
        *                        (May be <code>null</code>)
        * @param CopyMacroException Exception occured during copy
        */
  -    private synchronized void copyObject(SlideToken token, String sourceUri,
  -                                         String destinationUri, MacroParameters parameters, CopyMacroException e,
  -                                         CopyRouteRedirector copyRedirector, CopyListener copyListener) {
  +    private void copyObject(SlideToken token, String sourceUri,
  +                            String destinationUri, MacroParameters parameters, CopyMacroException e,
  +                            CopyRouteRedirector copyRedirector, CopyListener copyListener) {
           
           Domain.debug("Copy object : from " + sourceUri + " to "
                            + destinationUri);
  @@ -610,6 +597,7 @@
               ObjectNode sourceNode =
                   structureHelper.retrieve(token, sourceUri, false);
               Enumeration sourceNodeChildren = sourceNode.enumerateChildren();
  +            ObjectNode destinationNode = null;
               
               // now let the client redirect
               if (copyRedirector != null) {  // TODO: dump re-directing
  @@ -631,8 +619,27 @@
               // Creating the copy
               if (parameters.isDeleteCreate() || !destinationExists) {
                   try {
  -                    structureHelper.create(token, sourceNode.copyObject(),
  -                                           destinationUri);
  +                    Map alreadyCopied = (Map)parameters.getParameter( ALREADY_COPIED );
  +                    
  +                    if (alreadyCopied.containsKey(sourceNode.getUuri())) {
  +                        // If a COPY request would cause a new resource to be created
  +                        // as a copy of an existing resource, and that COPY request
  +                        // has already created a copy of that existing resource,
  +                        // the COPY request instead creates another binding to the
  +                        // previous copy, instead of creating a new resource.
  +                        UriHandler destinationUh = new UriHandler(destinationUri);
  +                        UriHandler destinationParentUh = destinationUh.getParent();
  +                        String segment = destinationUh.getLastSegment();
  +                        destinationNode = structureHelper.retrieve( token, (String)alreadyCopied.get(sourceNode.getUuri()) );
  +                        ObjectNode destinationParentNode = structureHelper.retrieve( token, destinationParentUh.toString() );
  +                        structureHelper.addBinding( token, destinationParentNode, segment, destinationNode );
  +                    }
  +                    else {
  +                        structureHelper.create(token, sourceNode.copyObject(),
  +                                               destinationUri);
  +                        destinationNode = structureHelper.retrieve( token, destinationUri );
  +                        alreadyCopied.put( sourceNode.getUuri(), destinationNode.getUri() );
  +                    }
                   } catch (ObjectNotFoundException s){
                       throw new ConflictException(s.getObjectUri());
                   }
  
  
  
  1.13      +28 -33    jakarta-slide/src/share/org/apache/slide/macro/Macro.java
  
  Index: Macro.java
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/share/org/apache/slide/macro/Macro.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Macro.java	18 Aug 2003 06:49:20 -0000	1.12
  +++ Macro.java	21 Aug 2003 14:48:22 -0000	1.13
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -15,7 +15,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    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
  @@ -23,15 +23,15 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution, if
  - *    any, must include the following acknowlegement:  
  - *       "This product includes software developed by the 
  + *    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", "Slide", and "Apache Software
    *    Foundation" must not be used to endorse or promote products derived
  - *    from this software without prior written permission. For written 
  + *    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"
  @@ -59,46 +59,41 @@
    *
    * [Additional notices, if required by prior licensing conditions]
    *
  - */ 
  + */
   
   package org.apache.slide.macro;
   
  -import java.util.Enumeration;
  -import java.util.Vector;
  -import java.util.Date;
  -import org.apache.slide.common.*;
  -import org.apache.slide.structure.*;
  -import org.apache.slide.security.*;
  -import org.apache.slide.content.*;
  -import org.apache.slide.authenticate.CredentialsToken;
  +import org.apache.slide.common.SlideToken;
   
   /**
    * Macro helper class.
  - * 
  + *
    * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
    * @version $Revision$
    */
   public interface Macro {
       
  -    public static final MacroParameters DEFAULT_PARAMETERS = 
  +    public static final MacroParameters DEFAULT_PARAMETERS =
           new MacroParameters();
       
  -    public static final MacroParameters RECURSIVE_OVERWRITE_PARAMETERS = 
  +    public static final MacroParameters RECURSIVE_OVERWRITE_PARAMETERS =
           new MacroParameters(true, true);
       
  +    public final static String ALREADY_COPIED = "alreadyCopied";
  +    
       
       // ------------------------------------------------------ Interface Methods
       
       
       /**
        * Recursive copy with overwrite macro.
  -     * 
  +     *
        * @param token Credentials token
        * @param sourceUri Uri of the source
        * @param destinationUri Uri of the destination
        * @exception CopyMacroException Generic Slide exception
        */
  -    void copy(SlideToken token, String sourceUri, 
  +    void copy(SlideToken token, String sourceUri,
                 String destinationUri)
           throws CopyMacroException, DeleteMacroException;
       
  @@ -132,14 +127,14 @@
       
       /**
        * Copy macro.
  -     * 
  +     *
        * @param token Credentials token
        * @param sourceUri Uri of the source
        * @param destinationUri Uri of the destination
        * @param parameters Macro parameters
        * @exception CopyMacroException Generic Slide exception
        */
  -    void copy(SlideToken token, String sourceUri, 
  +    void copy(SlideToken token, String sourceUri,
                 String destinationUri, MacroParameters parameters)
           throws CopyMacroException, DeleteMacroException;
       
  @@ -175,14 +170,14 @@
       
       /**
        * Recursive move with overwrite macro.
  -     * 
  +     *
        * @param token Credentials token
        * @param sourceUri Uri of the source
        * @param destinationUri Uri of the destination
        * @exception CopyMacroException Exception occured during copy
        * @exception DeleteMacroException Exception occured during deletion
        */
  -    void move(SlideToken token, String sourceUri, 
  +    void move(SlideToken token, String sourceUri,
                 String destinationUri)
           throws CopyMacroException, DeleteMacroException;
       
  @@ -216,7 +211,7 @@
       
       /**
        * Move macro.
  -     * 
  +     *
        * @param token Credentials token
        * @param sourceUri Uri of the source
        * @param destinationUri Uri of the destination
  @@ -224,7 +219,7 @@
        * @exception CopyMacroException Exception occured during copy
        * @exception DeleteMacroException Exception occured during deletion
        */
  -    void move(SlideToken token, String sourceUri, 
  +    void move(SlideToken token, String sourceUri,
                 String destinationUri, MacroParameters parameters)
           throws CopyMacroException, DeleteMacroException;
       
  @@ -260,7 +255,7 @@
       
       /**
        * Recursive delete.
  -     * 
  +     *
        * @param token Credentials token
        * @param targetUri Uri of the object to delete
        * @exception DeleteMacroException Generic Slide exception
  @@ -288,14 +283,14 @@
       
       /**
        * Delete macro.
  -     * 
  +     *
        * @param token Credentials token
        * @param targetUri Uri of the source
  -     * @param parameters Macro parameters, not used right now, 
  +     * @param parameters Macro parameters, not used right now,
        * so it can be null
        * @exception DeleteMacroException Generic Slide exception
        */
  -    void delete(SlideToken token, String targetUri, 
  +    void delete(SlideToken token, String targetUri,
                   MacroParameters parameters)
           throws DeleteMacroException;
       
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: slide-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-dev-help@jakarta.apache.org