db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r387324 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/ engine/org/apache/derby/io/ testing/org/apache/derbyTesting/functionTests/util/corruptio/
Date Mon, 20 Mar 2006 22:24:52 GMT
Author: djd
Date: Mon Mar 20 14:24:46 2006
New Revision: 387324

URL: http://svn.apache.org/viewcvs?rev=387324&view=rev
Log:
DERBY-538 (partial) Add a getURL method to the StorageFile interface of the virtual
file system layer. This will allow the standard URLClassLoader to access
jar files stored in a database, regradless of the file system implementation.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/InputStreamFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarDBFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/io/StorageFile.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/corruptio/CorruptFile.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java?rev=387324&r1=387323&r2=387324&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/CPFile.java Mon Mar 20 14:24:46
2006
@@ -25,6 +25,8 @@
 import java.io.InputStream;
 
 import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 /**
  * This class provides a class path based implementation of the StorageFile interface. It
is used by the
@@ -66,24 +68,7 @@
      */
     public boolean exists()
     {
-    	ClassLoader cl = Thread.currentThread().getContextClassLoader();
-    	if (cl != null)
-    		if (cl.getResource(path) != null)
-    			return true;
-    	// don't assume the context class loader is tied
-    	// into the class loader that loaded this class.
-    	cl = getClass().getClassLoader();
-		// Javadoc indicates implementations can use
-		// null as a return from Class.getClassLoader()
-		// to indicate the system/bootstrap classloader.
-    	if (cl != null)
-    	{
-    		return (cl.getResource(path) != null);
-    	}
-    	else
-    	{
-    		return ClassLoader.getSystemResource(path) != null;
-    	}
+    	return getURL() != null;
     } // end of exists
 
     /**
@@ -130,4 +115,32 @@
     	return is;
     	
     } // end of getInputStream
+    
+	/**
+     * Return a URL for this file (resource).
+     * 
+     * @see org.apache.derby.io.StorageFile#getURL()
+     */
+    public URL getURL() {
+
+        ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        URL myURL;
+        if (cl != null) {
+            myURL = cl.getResource(path);
+            if (myURL != null)
+                return myURL;
+        }
+
+        // don't assume the context class loader is tied
+        // into the class loader that loaded this class.
+        cl = getClass().getClassLoader();
+        // Javadoc indicates implementations can use
+        // null as a return from Class.getClassLoader()
+        // to indicate the system/bootstrap classloader.
+        if (cl != null) {
+            return cl.getResource(path);
+        } else {
+            return ClassLoader.getSystemResource(path);
+        }
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirFile.java?rev=387324&r1=387323&r2=387324&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/DirFile.java Mon Mar 20 14:24:46
2006
@@ -33,6 +33,8 @@
 import java.io.IOException;
 import java.io.FileNotFoundException;
 import java.io.RandomAccessFile;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 /**
  * This class provides a disk based implementation of the StorageFile interface. It is used
by the
@@ -261,4 +263,12 @@
         }
         return delete();
     } // end of deleteAll
+
+	/**
+	 * @see org.apache.derby.io.StorageFile#getURL()
+	 */
+	public URL getURL() throws MalformedURLException {
+		
+		return toURL();
+	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/InputStreamFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/InputStreamFile.java?rev=387324&r1=387323&r2=387324&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/InputStreamFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/InputStreamFile.java Mon Mar
20 14:24:46 2006
@@ -31,6 +31,8 @@
 import java.io.OutputStream;
 import java.io.IOException;
 import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 /**
  * This class provides the base for read-only stream implementations of the StorageFile interface.
It is used with the
@@ -417,4 +419,11 @@
     {
         return path;
     }
+    
+	/**
+	 * @see org.apache.derby.io.StorageFile#getURL()
+	 */
+	public URL getURL() throws MalformedURLException {
+		throw new MalformedURLException(toString());
+	}
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarDBFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarDBFile.java?rev=387324&r1=387323&r2=387324&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarDBFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/JarDBFile.java Mon Mar 20 14:24:46
2006
@@ -30,6 +30,8 @@
 import java.io.OutputStream;
 import java.io.IOException;
 import java.io.FileNotFoundException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
@@ -136,5 +138,18 @@
     public String toString()
     {
         return path;
+    }
+	/**
+     * Return a URL for this file (resource). Returns a URL according to the
+     * spec for java.net.JarURLConnection
+     * 
+     * @see org.apache.derby.io.StorageFile#getURL()
+     */
+    public URL getURL() throws MalformedURLException {
+        File pathFile = new File(storageFactory.zipData.getName());
+
+        String pathFileURL = pathFile.toURL().toString();
+
+        return new URL("jar:" + pathFileURL + "!/" + path);
     }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/io/StorageFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/io/StorageFile.java?rev=387324&r1=387323&r2=387324&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/io/StorageFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/io/StorageFile.java Mon Mar 20 14:24:46
2006
@@ -24,6 +24,8 @@
 import java.io.OutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
 
 /**
  * This interface abstracts file naming. Any method in this interface
@@ -128,6 +130,14 @@
     public String getName();
     
     /**
+     * Get a URL representing this file. A valid URL does not indicate the file exists,
+     * it may just be a URL that will fail on opening. Some implementations
+     * return null if the file does not exist. 
+     * @throws MalformedURLException File cannot be represented as a URL.
+     */
+    public URL getURL() throws MalformedURLException;
+    
+    /**
      * If the named file does not already exist then create it as an empty normal file.
      *
      * The implementation
@@ -277,11 +287,4 @@
      * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/io/RandomAccessFile.html">java.io.RandomAccessFile</a>
      */
     public StorageRandomAccessFile getRandomAccessFile( String mode) throws FileNotFoundException;
-
-    /**
-     * Get the file name for diagnostic purposes. Usually the same as getPath().
-     *
-     * @return the file name
-     */
-    public String toString();
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/corruptio/CorruptFile.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/corruptio/CorruptFile.java?rev=387324&r1=387323&r2=387324&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/corruptio/CorruptFile.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/corruptio/CorruptFile.java
Mon Mar 20 14:24:46 2006
@@ -29,6 +29,8 @@
 import java.io.IOException;
 import java.io.FileNotFoundException;
 import java.io.RandomAccessFile;
+import java.net.MalformedURLException;
+import java.net.URL;
 
 /**
  * This class provides proxy implementation of the StorageFile interface. It is
@@ -386,5 +388,10 @@
 	{
 		return realFile;
 	}
-
+	/**
+	 * @see org.apache.derby.io.StorageFile#getURL()
+	 */
+	public URL getURL() throws MalformedURLException {
+		throw new MalformedURLException(toString());
+	}
 }



Mime
View raw message