[jboss-cvs] JBossAS SVN: r93978 - in projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual: spi and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Sep 24 05:55:48 EDT 2009
Author: alesj
Date: 2009-09-24 05:55:48 -0400 (Thu, 24 Sep 2009)
New Revision: 93978
Added:
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPlugin.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPluginRegistry.java
Modified:
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
Log:
[JBVFS-124]; allow for plugable file handling.
TODO - tests.
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2009-09-24 08:48:32 UTC (rev 93977)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/file/FileSystemContext.java 2009-09-24 09:55:48 UTC (rev 93978)
@@ -44,6 +44,9 @@
import org.jboss.virtual.spi.LinkInfo;
import org.jboss.virtual.spi.VFSContextConstraints;
import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.FileHandlerPlugin;
+import org.jboss.virtual.spi.FileHandlerPluginRegistry;
+import org.jboss.virtual.spi.VFSContext;
/**
* FileSystemContext.
@@ -65,7 +68,7 @@
* @author <a href="strukelj at parsek.net">Marko Strukelj</a>
* @version $Revision: 1.1 $
*/
-public class FileSystemContext extends AbstractVFSContext
+public class FileSystemContext extends AbstractVFSContext implements FileHandlerPlugin
{
protected static final Logger staticLog = Logger.getLogger(FileSystemContext.class);
@@ -225,6 +228,16 @@
return root;
}
+ public int getRelativeOrder()
+ {
+ return Integer.MAX_VALUE;
+ }
+
+ public VirtualFileHandler createHandler(VFSContext context, VirtualFileHandler parent, File file, URI uri) throws IOException
+ {
+ return FileSystemContext.class.cast(context).createVirtualFileHandler(parent, file, file.toURI());
+ }
+
/**
* Create a new virtual file handler
*
@@ -239,36 +252,16 @@
if (file == null)
throw new IllegalArgumentException("Null file");
- String name = file.getName();
- if (file.isFile() && JarUtils.isArchive(name))
+ Set<FileHandlerPlugin> plugins = FileHandlerPluginRegistry.getInstance().getFileHandlerPlugins();
+ plugins.add(this); // add this to potential external plugins
+
+ for(FileHandlerPlugin plugin : plugins)
{
- if (exists(file) == false)
- return null;
-
- if (forceVfsJar)
- {
- try
- {
- return new JarHandler(this, parent, file, file.toURI().toURL(), name);
- }
- catch(IOException e)
- {
- log.debug("Exception while trying to handle file (" + name + ") as a jar: " + e.getMessage());
- }
- }
- else
- {
- try
- {
- return mountZipFS(parent, name, file);
- }
- catch (Exception e)
- {
- log.debug("IGNORING: Exception while trying to handle file (" + name + ") as a jar through ZipEntryContext: ", e);
- }
- }
+ VirtualFileHandler handler = plugin.createHandler(this, parent, file, file.toURI());
+ if (handler != null)
+ return handler;
}
- return createVirtualFileHandler(parent, file, getFileURI(file));
+ return null;
}
/**
@@ -309,20 +302,49 @@
* @throws IOException for any error accessing the file system
* @throws IllegalArgumentException for a null file
*/
- public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, File file, URI uri)
- throws IOException
+ public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, File file, URI uri) throws IOException
{
if (file == null)
throw new IllegalArgumentException("Null file");
if (uri == null)
throw new IllegalArgumentException("Null uri");
+ String name = file.getName();
+ if (file.isFile() && JarUtils.isArchive(name))
+ {
+ if (exists(file) == false)
+ return null;
+
+ if (forceVfsJar)
+ {
+ try
+ {
+ return new JarHandler(this, parent, file, file.toURI().toURL(), name);
+ }
+ catch(IOException e)
+ {
+ log.debug("Exception while trying to handle file (" + name + ") as a jar: " + e.getMessage());
+ }
+ }
+ else
+ {
+ try
+ {
+ return mountZipFS(parent, name, file);
+ }
+ catch (Exception e)
+ {
+ log.debug("IGNORING: Exception while trying to handle file (" + name + ") as a jar through ZipEntryContext: ", e);
+ }
+ }
+ }
+
VirtualFileHandler handler = null;
if(VFSUtils.isLink(file.getName()))
{
handler = createLinkHandler(parent, file, null);
}
- else if (exists(file) == false && parent != null)
+ else if (parent != null && exists(file) == false)
{
// See if we can resolve this to a link in the parent
if (parent instanceof FileHandler)
@@ -346,8 +368,7 @@
* @return newly created <tt>LinkHandler</tt>
* @throws IOException for any error
*/
- LinkHandler createLinkHandler(VirtualFileHandler parent, File file, String linkNameCondition)
- throws IOException
+ LinkHandler createLinkHandler(VirtualFileHandler parent, File file, String linkNameCondition) throws IOException
{
URI uri = file.toURI();
LinkHandler handler = null;
@@ -391,7 +412,7 @@
* @return true if file exists
* @throws IOException for any error
*/
- protected boolean exists(File file) throws IOException
+ public boolean exists(File file) throws IOException
{
// if force case sensitive is enabled - extra check is required
boolean isCaseSensitive = forceCaseSensitive;
Added: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPlugin.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPlugin.java (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPlugin.java 2009-09-24 09:55:48 UTC (rev 93978)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.Comparator;
+
+/**
+ * This knows how to create a virtual file handler from a file or uri.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public interface FileHandlerPlugin
+{
+ /**
+ * Get relative order.
+ *
+ * @return the order number
+ */
+ int getRelativeOrder();
+
+ /**
+ * Create new virtual file handler from a file or uri.
+ *
+ * @param context the current context
+ * @param parent the parent virtual file handler
+ * @param file the current file
+ * @param uri the file's uri
+ * @return new virtual file handler or null if cannot create one
+ * @throws IOException for any error
+ */
+ VirtualFileHandler createHandler(VFSContext context, VirtualFileHandler parent, File file, URI uri) throws IOException;
+
+ /**
+ * The relative order comparator.
+ */
+ static Comparator<FileHandlerPlugin> COMPARATOR = new Comparator<FileHandlerPlugin>()
+ {
+ public int compare(FileHandlerPlugin fhp1, FileHandlerPlugin fhp2)
+ {
+ return fhp1.getRelativeOrder() - fhp2.getRelativeOrder();
+ }
+ };
+}
Added: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPluginRegistry.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPluginRegistry.java (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/FileHandlerPluginRegistry.java 2009-09-24 09:55:48 UTC (rev 93978)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.spi;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.util.collection.ConcurrentSet;
+
+/**
+ * Singleton file handler plugin registry
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class FileHandlerPluginRegistry
+{
+ /** The singleton instance */
+ private static FileHandlerPluginRegistry instance = new FileHandlerPluginRegistry();
+
+ /** The file handler plugins */
+ private Set<FileHandlerPlugin> plugins = new ConcurrentSet<FileHandlerPlugin>();
+
+ private FileHandlerPluginRegistry()
+ {
+ }
+
+ /**
+ * Get instance.
+ *
+ * @return get instance
+ */
+ public static FileHandlerPluginRegistry getInstance()
+ {
+ return instance;
+ }
+
+ /**
+ * Add file handler plugin.
+ *
+ * @param plugin the plugin
+ * @return see Set#add
+ */
+ public boolean addFileHandlerPlugin(FileHandlerPlugin plugin)
+ {
+ return plugins.add(plugin);
+ }
+
+ /**
+ * Remove file handler plugin.
+ *
+ * @param plugin the plugin
+ * @return see Set#remove
+ */
+ public boolean removeFileHandlerPlugin(FileHandlerPlugin plugin)
+ {
+ return plugins.remove(plugin);
+ }
+
+ /**
+ * Return a copy of plugins.
+ *
+ * @return the plugins copy
+ */
+ public Set<FileHandlerPlugin> getFileHandlerPlugins()
+ {
+ Set<FileHandlerPlugin> copy = new TreeSet<FileHandlerPlugin>(FileHandlerPlugin.COMPARATOR);
+ copy.addAll(plugins);
+ return copy;
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list