[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: VFS cache as impl detail, to what extent
alesj
do-not-reply at jboss.com
Thu Jan 22 07:54:29 EST 2009
"dimitris at jboss.org" wrote : Why VFS::getCacheFile needs to be part of the API? One implementation could support caching, another one not.
Sure, hence my proposed change:
| Index: src/main/java/org/jboss/virtual/VFS.java
| ===================================================================
| --- src/main/java/org/jboss/virtual/VFS.java (revision 83078)
| +++ src/main/java/org/jboss/virtual/VFS.java (working copy)
| @@ -158,6 +158,20 @@
| }
|
| /**
| + * Create new root
| + *
| + * @param rootURI the root url
| + * @return the virtual file
| + * @throws IOException if there is a problem accessing the VFS
| + * @throws IllegalArgumentException if the rootURL
| + */
| + public static VirtualFile createNewRoot(URI rootURI) throws IOException
| + {
| + VFS vfs = getVFS(rootURI);
| + return vfs.getRoot();
| + }
| +
| + /**
| * Get the root virtual file
| *
| * @param rootURI the root uri
| @@ -167,8 +181,9 @@
| */
| public static VirtualFile getRoot(URI rootURI) throws IOException
| {
| - VFS vfs = getVFS(rootURI);
| - return vfs.getRoot();
| + VFSCache cache = VFSCacheFactory.getInstance();
| + VirtualFile file = cache.getFile(rootURI);
| + return (file != null) ? file : createNewRoot(rootURI);
| }
|
| /**
| @@ -182,12 +197,12 @@
| * @return the cached virtual file
| * @throws IOException for any error
| * @throws IllegalArgumentException if the rootURL is null
| + * @deprecated use getRoot
| */
| + @Deprecated
| public static VirtualFile getCachedFile(URI rootURI) throws IOException
| {
| - VFSCache cache = VFSCacheFactory.getInstance();
| - VirtualFile file = cache.getFile(rootURI);
| - return (file != null) ? file : getRoot(rootURI);
| + return getRoot(rootURI);
| }
|
| /**
| @@ -202,8 +217,8 @@
| @SuppressWarnings("deprecation")
| public static VirtualFile getVirtualFile(URI rootURI, String name) throws IOException
| {
| - VFS vfs = getVFS(rootURI);
| - return vfs.findChild(name);
| + VirtualFile root = getRoot(rootURI);
| + return root.findChild(name);
| }
|
| /**
| @@ -225,20 +240,35 @@
| }
|
| /**
| - * Get the root virtual file
| + * Create new root
| *
| * @param rootURL the root url
| * @return the virtual file
| * @throws IOException if there is a problem accessing the VFS
| * @throws IllegalArgumentException if the rootURL
| */
| - public static VirtualFile getRoot(URL rootURL) throws IOException
| + public static VirtualFile createNewRoot(URL rootURL) throws IOException
| {
| VFS vfs = getVFS(rootURL);
| return vfs.getRoot();
| }
|
| /**
| + * Get the root virtual file
| + *
| + * @param rootURL the root url
| + * @return the virtual file
| + * @throws IOException if there is a problem accessing the VFS
| + * @throws IllegalArgumentException if the rootURL
| + */
| + public static VirtualFile getRoot(URL rootURL) throws IOException
| + {
| + VFSCache cache = VFSCacheFactory.getInstance();
| + VirtualFile file = cache.getFile(rootURL);
| + return (file != null) ? file : createNewRoot(rootURL);
| + }
| +
| + /**
| * Get cached file.
| *
| * If VFSContext matching the rootURL parameter is cached
| @@ -249,12 +279,12 @@
| * @return the cached virtual file
| * @throws IOException for any error
| * @throws IllegalArgumentException if the rootURL is null
| + * @deprecated use getRoot
| */
| + @Deprecated
| public static VirtualFile getCachedFile(URL rootURL) throws IOException
| {
| - VFSCache cache = VFSCacheFactory.getInstance();
| - VirtualFile file = cache.getFile(rootURL);
| - return (file != null) ? file : getRoot(rootURL);
| + return getRoot(rootURL);
| }
|
| /**
| @@ -269,8 +299,8 @@
| @SuppressWarnings("deprecation")
| public static VirtualFile getVirtualFile(URL rootURL, String name) throws IOException
| {
| - VFS vfs = getVFS(rootURL);
| - return vfs.findChild(name);
| + VirtualFile root = getRoot(rootURL);
| + return root.findChild(name);
| }
|
| /**
|
So, in non-cached env, createNewRoot == getRoot.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4203988#4203988
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4203988
More information about the jboss-dev-forums
mailing list