commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozeigerm...@apache.org
Subject cvs commit: jakarta-commons/transaction/src/java/org/apache/commons/transaction/file JDK14URLEncodeIdMapper.java ResourceIdToPathMapper.java URLEncodeIdMapper.java FileResourceManager.java
Date Sat, 18 Dec 2004 23:19:09 GMT
ozeigermann    2004/12/18 15:19:09

  Modified:    transaction build.xml RELEASE-NOTES.txt
               transaction/src/java/org/apache/commons/transaction/file
                        FileResourceManager.java
  Added:       transaction/src/java/org/apache/commons/transaction/file
                        JDK14URLEncodeIdMapper.java
                        ResourceIdToPathMapper.java URLEncodeIdMapper.java
  Log:
  Added support for configurable resource id to path mapping as
  proposed by Antranig Basman
  
  Revision  Changes    Path
  1.9       +2 -1      jakarta-commons/transaction/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/build.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- build.xml	17 Dec 2004 12:09:32 -0000	1.8
  +++ build.xml	18 Dec 2004 23:19:08 -0000	1.9
  @@ -155,13 +155,14 @@
     =================================================================== 
     -->
   
  -  <target name="build" depends="prepare" description="Compiles the main classes">
  +  <target name="build" depends="prepare,detect" description="Compiles the main classes">
       <javac destdir="${build.classes}"
         target="${compile.target}"
         debug="${compile.debug}"
         deprecation="${compile.deprecation}"
         optimize="${compile.optimize}" >
         <exclude name="**/jca/**"/>
  +      <exclude name="**/JDK14URLEncodeIdMapper.java" unless="jvm14.present"/>
         <src path="${java.dir}"/>
         <classpath refid="classpath" />
       </javac>
  
  
  
  1.8       +6 -2      jakarta-commons/transaction/RELEASE-NOTES.txt
  
  Index: RELEASE-NOTES.txt
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/RELEASE-NOTES.txt,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RELEASE-NOTES.txt	17 Dec 2004 00:33:38 -0000	1.7
  +++ RELEASE-NOTES.txt	18 Dec 2004 23:19:08 -0000	1.8
  @@ -27,16 +27,20 @@
   ENHANCEMENTS FROM 1.0
   ---------------------
   
  +Locking:
   - Extended and less excentric lock manager
  -- Deadlock detection for all lock managers, file store, and pessimistic map
  -- Flexible preference mechanism 
   
  +File:
  +- Confiburable resource id to path mapping
   
   NEW FEATURES FROM 1.0
   ---------------------
   
  +Locking:
   - new ReadWriteLockManager for most intuitive read/write lock usage
   - new read/write/upgrade locking mechanism
  +- Deadlock detection for all lock managers, file store, and pessimistic map
  +- Flexible preference locking mechanism 
   
   MINOR INCOMPATIBILITIES TO 1.0
   -----------------------------------------
  
  
  
  1.5       +29 -25    jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/FileResourceManager.java
  
  Index: FileResourceManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/FileResourceManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FileResourceManager.java	16 Dec 2004 17:33:53 -0000	1.4
  +++ FileResourceManager.java	18 Dec 2004 23:19:09 -0000	1.5
  @@ -34,8 +34,6 @@
   import java.io.InputStreamReader;
   import java.io.OutputStream;
   import java.io.OutputStreamWriter;
  -import java.io.UnsupportedEncodingException;
  -import java.net.URLEncoder;
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.HashMap;
  @@ -44,7 +42,6 @@
   import java.util.Iterator;
   import java.util.Collections;
   
  -import org.apache.commons.codec.binary.Base64;
   import org.apache.commons.transaction.locking.GenericLock;
   import org.apache.commons.transaction.locking.GenericLockManager;
   import org.apache.commons.transaction.locking.LockException;
  @@ -185,7 +182,6 @@
   
       protected String workDir;
       protected String storeDir;
  -    protected boolean urlEncodePath = false;
       protected boolean cleanUp = true;
       protected boolean dirty = false;
       protected int operationMode = OPERATION_MODE_STOPPED;
  @@ -197,6 +193,8 @@
       protected Map globalTransactions;
       protected List globalOpenResources;
       protected LockManager lockManager;
  +    
  +    protected ResourceIdToPathMapper idMapper = null;
   
       /*
        * --- ctor and general getter / setter methods ---
  @@ -231,11 +229,29 @@
           boolean urlEncodePath,
           LoggerFacade logger,
           boolean debug) {
  +        this(storeDir, workDir, urlEncodePath ? new URLEncodeIdMapper() : null, logger,
false);
  +    }
  +
  +    /**
  +     * Creates a new resouce manager operation on the specified directories.
  +     * 
  +     * @param storeDir directory where main data should go after commit
  +     * @param workDir directory where transactions store temporary data 
  +     * @param idMapper mapper for resourceId to path
  +     * @param logger the logger to be used by this store
  +     * @param debug if set to <code>true</code> logs all locking information
to "transaction.log" for debugging inspection 
  +     */
  +    public FileResourceManager(
  +        String storeDir,
  +        String workDir,
  +        ResourceIdToPathMapper idMapper,
  +        LoggerFacade logger,
  +        boolean debug) {
           this.workDir = workDir;
           this.storeDir = storeDir;
  -        this.urlEncodePath = urlEncodePath;
           this.logger = logger;
           this.debug = debug;
  +        this.idMapper = idMapper;
       }
   
       /**
  @@ -942,22 +958,10 @@
       protected String assureLeadingSlash(Object pathObject) {
           String path = "";
           if (pathObject != null) {
  -            path = pathObject.toString();
  -            if (urlEncodePath) {
  -                try {
  -                    // XXX not allowed as for JDK1.4 
  -                    //                    path = URLEncoder.encode(path, "UTF-8");
  -                    // XXX weired replacement for the fine method above
  -                    // using this combination as a simple URLEncoder.encode without
  -                    // charset may fail depending on local settings
  -                    // for this reason the string will be encoded into base64 consisting
  -                    // of ascii characters only
  -                    // a further URL encoding is need as base64 might contain '/' which
  -                    // might be a problem for some file systems 
  -                    path = new String(Base64.encodeBase64(path.getBytes("UTF-8")), "ASCII");
  -                    path = URLEncoder.encode(path);
  -                } catch (UnsupportedEncodingException e) {
  -                }
  +            if (idMapper != null) {
  +                path = idMapper.getPathForId(pathObject);
  +            } else {
  +                path = pathObject.toString();
               }
               if (path.length() > 0 && path.charAt(0) != '/' && path.charAt(0)
!= '\\') {
                   path = "/" + path;
  
  
  
  1.1                  jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/JDK14URLEncodeIdMapper.java
  
  Index: JDK14URLEncodeIdMapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/JDK14URLEncodeIdMapper.java,v
1.1 2004/12/18 23:19:09 ozeigermann Exp $
   * $Revision: 1.1 $
   * $Date: 2004/12/18 23:19:09 $
   *
   * ====================================================================
   *
   * Copyright 1999-2002 The Apache Software Foundation 
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  package org.apache.commons.transaction.file;
  
  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;
  
  /**
   *  
   */
  public class JDK14URLEncodeIdMapper implements ResourceIdToPathMapper {
      public String getPathForId(Object resourceId) {
          String path = resourceId.toString();
          try {
              path = URLEncoder.encode(path, "UTF-8");
          } catch (UnsupportedEncodingException e) {
              // we know this will not happen
          }
          return path;
      }
  }
  
  
  1.1                  jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/ResourceIdToPathMapper.java
  
  Index: ResourceIdToPathMapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/ResourceIdToPathMapper.java,v
1.1 2004/12/18 23:19:09 ozeigermann Exp $
   * $Revision: 1.1 $
   * $Date: 2004/12/18 23:19:09 $
   *
   * ====================================================================
   *
   * Copyright 1999-2002 The Apache Software Foundation 
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  package org.apache.commons.transaction.file;
  
  /**
   * Mapper from a resourceId to a path string.
   *
   */
  public interface ResourceIdToPathMapper {
      /**
       * Maps the resource id object to a path string. 
       * 
       * @param resourceId the resource id
       * @return the path string
       */
      String getPathForId(Object resourceId);
  }
  
  
  
  1.1                  jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/URLEncodeIdMapper.java
  
  Index: URLEncodeIdMapper.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/transaction/src/java/org/apache/commons/transaction/file/URLEncodeIdMapper.java,v
1.1 2004/12/18 23:19:09 ozeigermann Exp $
   * $Revision: 1.1 $
   * $Date: 2004/12/18 23:19:09 $
   *
   * ====================================================================
   *
   * Copyright 1999-2002 The Apache Software Foundation 
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  
  package org.apache.commons.transaction.file;
  
  import java.io.UnsupportedEncodingException;
  import java.net.URLEncoder;
  
  import org.apache.commons.codec.binary.Base64;
  
  /**
   *
   */
  public class URLEncodeIdMapper implements ResourceIdToPathMapper {
      public String getPathForId(Object resourceId) {
          String path = resourceId.toString();
          try {
              // XXX weired replacement for the fine JDK1.4 URLEncoder.encode(path, "UTF-8")

              // method 
              // using this combination as a simple URLEncoder.encode without
              // charset may fail depending on local settings
              // for this reason the string will be encoded into base64 consisting
              // of ascii characters only
              // a further URL encoding is need as base64 might contain '/' which
              // might be a problem for some file systems 
              path = new String(Base64.encodeBase64(path.getBytes("UTF-8")), "ASCII");
              path = URLEncoder.encode(path);
          } catch (UnsupportedEncodingException e) {
              // we know this will not happen
          }
          return path;
      }
  }
  
  
  

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


Mime
View raw message