[Jboss-cvs] JBossAS SVN: r56686 - in projects/microcontainer/trunk/container/src/main/org/jboss/virtual: . plugins/context plugins/context/file plugins/context/jar spi
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Sep 8 17:02:49 EDT 2006
Author: scott.stark at jboss.org
Date: 2006-09-08 17:02:36 -0400 (Fri, 08 Sep 2006)
New Revision: 56686
Added:
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURIHandler.java
Modified:
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVFSContext.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContextFactory.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContext.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContextFactory.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContext.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactory.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java
projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java
Log:
Update to use URI as the primary identifier.
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VFS.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -22,6 +22,8 @@
package org.jboss.virtual;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
@@ -35,6 +37,7 @@
* Virtual File System
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class VFS
@@ -48,6 +51,7 @@
* @param rootURL the root url
* @return the virtual file system
* @throws IOException if there is a problem accessing the VFS
+ * @throws URISyntaxException if the URL is not a valid URI
* @throws IllegalArgumentException if the rootURL is null
*/
public static VFS getVFS(URL rootURL) throws IOException
@@ -56,6 +60,20 @@
VFSContext context = factory.getVFS(rootURL);
return context.getVFS();
}
+ /**
+ * Get the virtual file system for a root uri
+ *
+ * @param rootURI the root URI
+ * @return the virtual file system
+ * @throws IOException if there is a problem accessing the VFS
+ * @throws IllegalArgumentException if the rootURL is null
+ */
+ public static VFS getVFS(URI rootURI) throws IOException
+ {
+ VFSContextFactory factory = VFSContextFactoryLocator.getFactory(rootURI);
+ VFSContext context = factory.getVFS(rootURI);
+ return context.getVFS();
+ }
/**
* Get a virtual file
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/VirtualFile.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -25,6 +25,8 @@
import java.io.InputStream;
import java.io.Serializable;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.List;
@@ -111,12 +113,24 @@
*
* @return the full URL to the VF in the VFS.
* @throws MalformedURLException if a url cannot be parsed
+ * @throws URISyntaxException if a uri cannot be parsed
* @throws IllegalStateException if the file is closed
*/
- public URL toURL() throws MalformedURLException
+ public URL toURL() throws MalformedURLException, URISyntaxException
{
- return getHandler().toURL();
+ return getHandler().toURI().toURL();
}
+ /**
+ * Get the VF URI (file://root/org/jboss/X.java)
+ *
+ * @return the full URI to the VF in the VFS.
+ * @throws URISyntaxException if a uri cannot be parsed
+ * @throws IllegalStateException if the file is closed
+ */
+ public URI toURI() throws URISyntaxException
+ {
+ return getHandler().toURI();
+ }
/**
* When the file was last modified
Added: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURIHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURIHandler.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURIHandler.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -0,0 +1,113 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.virtual.plugins.context;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.net.URI;
+
+import org.jboss.virtual.spi.VFSContext;
+import org.jboss.virtual.spi.VirtualFileHandler;
+
+/**
+ * URIHandler stub.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractURIHandler extends AbstractVirtualFileHandler
+ implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ /** The uri */
+ private final URI uri;
+
+ /**
+ * Create a newURLHandler.
+ *
+ * @param context the context
+ * @param parent the parent
+ * @param url the url
+ * @param name the name
+ * @throws IllegalArgumentException for a null context, vfsPath or url
+ */
+ public AbstractURIHandler(VFSContext context, VirtualFileHandler parent, URI uri, String name)
+ {
+ super(context, parent, name);
+ if (uri == null)
+ throw new IllegalArgumentException("Null uri");
+ this.uri = uri;
+ }
+
+ /**
+ * Get the uri
+ *
+ * @return the uri
+ */
+ public URI getURI()
+ {
+ return uri;
+ }
+
+ public long getLastModified() throws IOException
+ {
+ checkClosed();
+ return 0;
+ }
+
+ public long getSize() throws IOException
+ {
+ checkClosed();
+ return 0;
+ }
+
+ public boolean isArchive() throws IOException
+ {
+ checkClosed();
+ return false;
+ }
+
+ public boolean isFile() throws IOException
+ {
+ checkClosed();
+ return isDirectory() == false;
+ }
+
+ public boolean isHidden() throws IOException
+ {
+ checkClosed();
+ return false;
+ }
+
+ public InputStream openStream() throws IOException
+ {
+ checkClosed();
+ return null;
+ }
+
+ public URI toURI()
+ {
+ return uri;
+ }
+}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractURLHandler.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -24,6 +24,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
@@ -109,8 +111,8 @@
return url.openStream();
}
- public URL toURL()
+ public URI toURI() throws URISyntaxException
{
- return url;
+ return url.toURI();
}
}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVFSContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVFSContext.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVFSContext.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -22,6 +22,8 @@
package org.jboss.virtual.plugins.context;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.Map;
@@ -49,24 +51,36 @@
private VFS vfs;
/** The root url */
- private final URL rootURL;
+ private final URI rootURI;
/** Options associated with the root URL */
private Map<String, String> rootOptions;
/**
* Create a new AbstractVFSContext.
*
- * @param rootURL the root url
- * @throws IllegalArgumentException if rootURL is null
+ * @param rootURI the root url
+ * @throws IllegalArgumentException if rootURI is null
*/
- protected AbstractVFSContext(URL rootURL)
+ protected AbstractVFSContext(URI rootURI)
{
- if (rootURL == null)
- throw new IllegalArgumentException("Null rootURL");
- this.rootURL = rootURL;
- String query = rootURL.getQuery();
+ if (rootURI == null)
+ throw new IllegalArgumentException("Null rootURI");
+ this.rootURI = rootURI;
+ String query = rootURI.getQuery();
rootOptions = VFSUtils.parseURLQuery(query);
}
+ /**
+ * Create a new AbstractVFSContext.
+ *
+ * @param rootURI the root url
+ * @throws URISyntaxException
+ * @throws IllegalArgumentException if rootURI is null
+ */
+ protected AbstractVFSContext(URL rootURL)
+ throws URISyntaxException
+ {
+ this(rootURL.toURI());
+ }
public VFS getVFS()
{
@@ -75,9 +89,9 @@
return vfs;
}
- public URL getRootURL()
+ public URI getRootURI()
{
- return rootURL;
+ return rootURI;
}
public Map<String, String> getOptions()
@@ -187,7 +201,7 @@
buffer.append('@');
buffer.append(System.identityHashCode(this));
buffer.append('[');
- buffer.append(rootURL);
+ buffer.append(rootURI);
buffer.append(']');
return buffer.toString();
}
@@ -195,7 +209,7 @@
@Override
public int hashCode()
{
- return rootURL.hashCode();
+ return rootURI.hashCode();
}
@Override
@@ -206,6 +220,6 @@
if (obj == null || obj instanceof VFSContext == false)
return false;
VFSContext other = (VFSContext) obj;
- return rootURL.equals(other.getRootURL());
+ return rootURI.equals(other.getRootURI());
}
}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -28,6 +28,7 @@
import java.io.ObjectInputStream.GetField;
import java.io.ObjectOutputStream.PutField;
import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -37,8 +38,6 @@
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.plugins.vfs.helpers.PathTokenizer;
import org.jboss.virtual.spi.VFSContext;
-import org.jboss.virtual.spi.VFSContextFactory;
-import org.jboss.virtual.spi.VFSContextFactoryLocator;
import org.jboss.virtual.spi.VirtualFileHandler;
/**
@@ -315,9 +314,9 @@
{
try
{
- return toURL().toString();
+ return toURI().toString();
}
- catch (MalformedURLException ignored)
+ catch (URISyntaxException ignored)
{
return "<unknown>";
}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileHandler.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -25,6 +25,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
@@ -57,7 +59,7 @@
* @param file the file
* @param url the url
* @throws IOException for an error accessing the file system
- * @throws IllegalArgumentException for a null context, url or vfsPath
+ * @throws IllegalArgumentException for a null context, url
*/
public FileHandler(FileSystemContext context, VirtualFileHandler parent, File file, URL url) throws IOException
{
@@ -67,6 +69,20 @@
if (file.exists() == false)
throw new FileNotFoundException("File does not exist: " + file.getCanonicalPath());
}
+ /**
+ * Create a new FileHandler
+ *
+ * @param context the context
+ * @param parent the parent
+ * @param file the file
+ * @param url the url
+ * @throws IOException for an error accessing the file system
+ * @throws IllegalArgumentException for a null context, uri
+ */
+ public FileHandler(FileSystemContext context, VirtualFileHandler parent, File file, URI uri) throws IOException
+ {
+ this(context, parent, file, uri.toURL());
+ }
@Override
public FileSystemContext getVFSContext()
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -23,6 +23,8 @@
import java.io.File;
import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import org.jboss.virtual.VFSUtils;
@@ -54,12 +56,12 @@
* @throws IOException for any error accessing the file system
* @throws IllegalArgumentException for a null url
*/
- private static File getFile(URL url) throws IOException
+ private static File getFile(URI uri) throws IOException
{
- if (url == null)
- throw new IllegalArgumentException("Null url");
+ if (uri == null)
+ throw new IllegalArgumentException("Null uri");
- return new File(url.getPath());
+ return new File(uri);
}
/**
@@ -70,14 +72,22 @@
* @throws IOException for any error accessing the file system
* @throws IllegalArgumentException for a null file
*/
- private static URL getFileURL(File file) throws IOException
+ private static URI getFileURI(File file) throws IOException
{
if (file == null)
throw new IllegalArgumentException("Null file");
- URL url = file.toURL();
+ URI url = file.toURI();
String path = url.getPath();
path = VFSUtils.fixName(path);
- return new URL("file", null, path);
+ try
+ {
+ return new URI("file", null, path, null);
+ }
+ catch(URISyntaxException e)
+ {
+ // Should not be possible
+ throw new IllegalStateException("Failed to convert file.toURI", e);
+ }
}
/**
@@ -86,10 +96,20 @@
* @param rootURL the root url
* @throws IOException for an error accessing the file system
*/
- public FileSystemContext(URL rootURL) throws IOException
+ public FileSystemContext(URL rootURL) throws IOException, URISyntaxException
{
- this(rootURL, getFile(rootURL));
+ this(rootURL.toURI());
}
+
+ /**
+ *
+ * @param rootURI
+ * @throws IOException
+ */
+ public FileSystemContext(URI rootURI) throws IOException
+ {
+ this(rootURI, getFile(rootURI));
+ }
/**
* Create a new FileSystemContext.
@@ -98,11 +118,11 @@
* @throws IOException for an error accessing the file system
* @throws IllegalArgumentException for a null file
*/
- public FileSystemContext(File file) throws IOException
+ public FileSystemContext(File file) throws IOException, URISyntaxException
{
- this(getFileURL(file), file);
+ this(getFileURI(file), file);
}
-
+
/**
* Create a new FileSystemContext.
*
@@ -110,7 +130,7 @@
* @param file the file
* @throws IOException for an error accessing the file system
*/
- private FileSystemContext(URL rootURL, File file) throws IOException
+ private FileSystemContext(URI rootURL, File file) throws IOException
{
super(rootURL);
root = createVirtualFileHandler(null, file);
@@ -136,10 +156,10 @@
if (file == null)
throw new IllegalArgumentException("Null file");
- URL fileURL = getFileURL(file);
+ URI fileURL = getFileURI(file);
if (file.isFile() && JarUtils.isArchive(file.getName()))
{
- URL url = JarUtils.createJarURL(fileURL);
+ URL url = JarUtils.createJarURL(file.toURL());
String name = file.getName();
try
{
@@ -163,14 +183,14 @@
* @throws IOException for any error accessing the file system
* @throws IllegalArgumentException for a null file
*/
- public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, File file, URL url) throws IOException
+ public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, File file, URI uri) throws IOException
{
if (file == null)
throw new IllegalArgumentException("Null file");
- if (url == null)
- throw new IllegalArgumentException("Null url");
+ if (uri == null)
+ throw new IllegalArgumentException("Null uri");
- return new FileHandler(this, parent, file, url);
+ return new FileHandler(this, parent, file, uri);
}
@Override
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContextFactory.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContextFactory.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/file/FileSystemContextFactory.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -21,6 +21,9 @@
*/
package org.jboss.virtual.plugins.context.file;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.io.IOException;
@@ -46,6 +49,19 @@
public VFSContext getVFS(URL root) throws IOException
{
+ try
+ {
+ return new FileSystemContext(root);
+ }
+ catch(URISyntaxException e)
+ {
+ MalformedURLException ex = new MalformedURLException("non-URI compliant URL");
+ ex.initCause(e);
+ throw ex;
+ }
+ }
+ public VFSContext getVFS(URI root) throws IOException
+ {
return new FileSystemContext(root);
}
}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/AbstractJarHandler.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -22,6 +22,8 @@
package org.jboss.virtual.plugins.context.jar;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
@@ -194,7 +196,15 @@
// Question: Why doesn't this work properly?
// URL url = new URL(parent.toURL(), entry.getName());
StringBuilder buffer = new StringBuilder();
- buffer.append(parent.toURL());
+ try
+ {
+ buffer.append(parent.toURI());
+ }
+ catch(URISyntaxException e)
+ {
+ // Should not happen
+ throw new MalformedURLException(e.getMessage());
+ }
if (buffer.charAt(buffer.length()-1) != '/')
buffer.append('/');
buffer.append(entry.getName());
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContext.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContext.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -22,6 +22,7 @@
package org.jboss.virtual.plugins.context.jar;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.net.URL;
import org.jboss.virtual.VirtualFile;
@@ -49,7 +50,7 @@
* @param rootURL the root url
* @throws IOException for an error accessing the file system
*/
- public JarContext(URL rootURL) throws IOException
+ public JarContext(URL rootURL) throws IOException, URISyntaxException
{
super(rootURL);
root = createVirtualFileHandler(null, rootURL);
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContextFactory.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContextFactory.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/JarContextFactory.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -21,9 +21,13 @@
*/
package org.jboss.virtual.plugins.context.jar;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.io.IOException;
+import org.jboss.virtual.plugins.context.file.FileSystemContext;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VFSContextFactory;
@@ -46,6 +50,28 @@
public VFSContext getVFS(URL root) throws IOException
{
- return new JarContext(root);
+ try
+ {
+ return new JarContext(root);
+ }
+ catch(URISyntaxException e)
+ {
+ MalformedURLException ex = new MalformedURLException("non-URI compliant URL");
+ ex.initCause(e);
+ throw ex;
+ }
}
+ public VFSContext getVFS(URI root) throws IOException
+ {
+ try
+ {
+ return new JarContext(root.toURL());
+ }
+ catch(URISyntaxException e)
+ {
+ MalformedURLException ex = new MalformedURLException("non-URI compliant URL");
+ ex.initCause(e);
+ throw ex;
+ }
+ }
}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/plugins/context/jar/NestedJarFromStream.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -13,6 +13,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
@@ -173,11 +175,18 @@
}
}
- public URL toURL() throws MalformedURLException
+ public URI toURI() throws URISyntaxException
{
- if( entryURL == null )
- entryURL = new URL(jarURL, getName());
- return entryURL;
+ try
+ {
+ if( entryURL == null )
+ entryURL = new URL(jarURL, getName());
+ }
+ catch(MalformedURLException e)
+ {
+ throw new URISyntaxException("Failed to create relative jarURL", e.getMessage());
+ }
+ return entryURL.toURI();
}
public String toString()
@@ -190,12 +199,12 @@
tmp.append(getSize());
tmp.append(",lastModified=");
tmp.append(lastModified);
- tmp.append(",URL=");
+ tmp.append(",URI=");
try
{
- tmp.append(toURL());
+ tmp.append(toURI());
}
- catch(MalformedURLException e)
+ catch(URISyntaxException e)
{
}
tmp.append(']');
@@ -211,13 +220,13 @@
{
try
{
- String url = toURL().toExternalForm() + "!/" + entry.getName();
+ String url = toURI().toASCIIString() + "!/" + entry.getName();
URL jecURL = new URL(url);
JarEntryContents jec = new JarEntryContents(getVFSContext(), this, entry, jecURL, zis, getPathName());
entries.put(entry.getName(), jec);
entry = zis.getNextEntry();
}
- catch(MalformedURLException e)
+ catch(URISyntaxException e)
{
e.printStackTrace();
}
@@ -363,9 +372,9 @@
}
}
- public URL toURL() throws MalformedURLException
+ public URI toURI() throws URISyntaxException
{
- return entryURL;
+ return entryURL.toURI();
}
public String toString()
@@ -378,12 +387,12 @@
tmp.append(entry.getSize());
tmp.append(",time=");
tmp.append(entry.getTime());
- tmp.append(",URL=");
+ tmp.append(",URI=");
try
{
- tmp.append(toURL());
+ tmp.append(toURI());
}
- catch(MalformedURLException e)
+ catch(URISyntaxException e)
{
}
tmp.append(']');
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContext.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContext.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContext.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -22,7 +22,7 @@
package org.jboss.virtual.spi;
import java.io.IOException;
-import java.net.URL;
+import java.net.URI;
import java.util.List;
import java.util.Map;
@@ -38,13 +38,12 @@
public interface VFSContext
{
/**
- * Get the root url
+ * Get the root uri
*
- * @return the root url
+ * @return the root uri
*/
- URL getRootURL();
-
-
+ URI getRootURI();
+
/**
* Get the VFS for this context
*
@@ -60,6 +59,11 @@
*/
VirtualFileHandler getRoot() throws IOException;
+ /**
+ * Get the context option settings
+ *
+ * @return a map of the context options
+ */
Map<String, String> getOptions();
/**
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactory.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactory.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactory.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -21,11 +21,12 @@
*/
package org.jboss.virtual.spi;
+import java.net.URI;
import java.net.URL;
import java.io.IOException;
/**
- * The entry point to obtaining a VFSContext for a given URL root mount point
+ * The entry point to obtaining a VFSContext for a given URL/URI root mount point
*
* @author Scott.Stark at jboss.org
* @author adrian at jboss.org
@@ -34,7 +35,7 @@
public interface VFSContextFactory
{
/**
- * Get the URL protocols this factory supports
+ * Get the URL protocols/URI schemes this factory supports
*
* @return list of supported protocols.
*/
@@ -46,6 +47,15 @@
* @param rootURL - the URL for the root of the virtual context
* @return the vfs context
* @throws IOException - thrown if the root cannot be opened/accessed
+ * @throws URISyntaxException - thrown if the URL cannot be converted to a URI
*/
VFSContext getVFS(URL rootURL) throws IOException;
+ /**
+ * Obtain a vfs context for the given root uri.
+ *
+ * @param rootURI - the URI for the root of the virtual context
+ * @return the vfs context
+ * @throws IOException - thrown if the root cannot be opened/accessed
+ */
+ VFSContext getVFS(URI rootURI) throws IOException;
}
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VFSContextFactoryLocator.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.net.URI;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -40,7 +41,7 @@
import org.jboss.virtual.plugins.context.jar.JarContextFactory;
/**
- * A singleton factory for locating VFSContextFactory instances given VFS root URLs.
+ * A singleton factory for locating VFSContextFactory instances given VFS root URIs.
*
* @author Scott.Stark at jboss.org
* @author adrian at jboss.org
@@ -145,6 +146,23 @@
String protocol = rootURL.getProtocol();
return factoryByProtocol.get(protocol);
}
+ /**
+ * Return the VFSContextFactory for the VFS mount point specified by the rootURI.
+ *
+ * @param rootURI - the URI to a VFS root
+ * @return the VFSContextFactory capable of handling the rootURI. This will be null
+ * if there is no factory registered for the rootURI scheme.
+ * @throws IllegalArgumentException if the rootURI is null
+ */
+ public static VFSContextFactory getFactory(URI rootURI)
+ {
+ if (rootURI == null)
+ throw new IllegalArgumentException("Null rootURI");
+
+ init();
+ String scheme = rootURI.getScheme();
+ return factoryByProtocol.get(scheme);
+ }
/**
* Initialises the default VFSContextFactorys<p>
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java 2006-09-08 20:39:40 UTC (rev 56685)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/virtual/spi/VirtualFileHandler.java 2006-09-08 21:02:36 UTC (rev 56686)
@@ -23,8 +23,10 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.Serializable;
import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.List;
import org.jboss.virtual.VirtualFile;
@@ -33,10 +35,10 @@
* A virtual file handler
*
* @author Scott.Stark at jboss.org
- * @author
+ * @author Adrian.Brock
* @version $Revision: 44334 $
*/
-public interface VirtualFileHandler
+public interface VirtualFileHandler extends Serializable
{
/**
* Get the simple VF name (X.java)
@@ -57,8 +59,9 @@
*
* @return the full URL to the VF in the VFS.
* @throws MalformedURLException if a url cannot be parsed
+ * @throws URISyntaxException
*/
- URL toURL() throws MalformedURLException;
+ URI toURI() throws URISyntaxException;
/**
* When the file was last modified
More information about the jboss-cvs-commits
mailing list