commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r348812 - in /jakarta/commons/sandbox/jci/trunk: ./ src/java/org/apache/commons/jci/readers/ src/java/org/apache/commons/jci/stores/
Date Thu, 24 Nov 2005 21:50:21 GMT
Author: tcurdt
Date: Thu Nov 24 13:50:10 2005
New Revision: 348812

URL: http://svn.apache.org/viewcvs?rev=348812&view=rev
Log:
thanks to Mark Proctor:

store classes in proper resource name manner,
added list methods to stores and readers,
added a new memory based resource reader


Added:
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
  (with props)
Modified:
    jakarta/commons/sandbox/jci/trunk/TODO
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
    jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java

Modified: jakarta/commons/sandbox/jci/trunk/TODO
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/TODO?rev=348812&r1=348811&r2=348812&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/TODO (original)
+++ jakarta/commons/sandbox/jci/trunk/TODO Thu Nov 24 13:50:10 2005
@@ -10,5 +10,4 @@
 o turn the JavaCompilerFactory into an interface and maybe provide a simple default impl
 o documentation
 o dependency analysis for proper re-try after errors
-o store resources as org/apache/my.class instead of org.apache.my
 o removing of anonymous classes if parent class is being removed

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java?rev=348812&r1=348811&r2=348812&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/FileResourceReader.java
Thu Nov 24 13:50:10 2005
@@ -16,6 +16,8 @@
 package org.apache.commons.jci.readers;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.commons.io.FileUtils;
 
@@ -25,22 +27,39 @@
  */
 public final class FileResourceReader implements ResourceReader {
 
-    private final File base;
+    private final File root;
 
-    public FileResourceReader( final File pBase ) {
-        base = pBase;        
+    public FileResourceReader( final File pRoot ) {
+        root = pRoot;        
     }
     
     public boolean isAvailable(String filename) {
-        return new File(base,filename).exists();
+        return new File(root,filename).exists();
     }
 
     public char[] getContent( final String fileName ) {
         try {
             return FileUtils.readFileToString(
-                    new File(base,fileName), "UTF-8").toCharArray();
+                    new File(root,fileName), "UTF-8").toCharArray();
         } catch(Exception e) {
         }
         return null;
     }
+    
+    public String[] list() {
+        final List files = new ArrayList();
+        list(root, files);
+        return (String[]) files.toArray(new String[files.size()]);
+    }
+
+    private void list(final File pFile, final List pFiles) {
+        if (pFile.isDirectory()) {
+            final File[] directoryFiles = pFile.listFiles();
+            for (int i=0; i < directoryFiles.length; i++) {
+                list(directoryFiles[i], pFiles);
+            }
+        } else {
+            pFiles.add(pFile.getAbsolutePath().substring(root.getAbsolutePath().length()+1));
+        }
+    }   
 }

Added: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java?rev=348812&view=auto
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
(added)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
Thu Nov 24 13:50:10 2005
@@ -0,0 +1,44 @@
+package org.apache.commons.jci.readers;
+
+import java.util.Map;
+import java.util.HashMap;
+
+public class MemoryResourceReader implements ResourceReader {
+    
+    private Map files;
+
+    public boolean isAvailable(final String pFileName) {
+        if (files == null) {
+            return false;
+        }
+
+        return files.containsKey( pFileName );
+    }
+    
+    public void addFile(final String pFileName, final char[] pFile) {
+        if (files == null) {
+            files = new HashMap();
+        }
+        
+        files.put(pFileName, pFile);
+    }
+    
+    public void removeFile(final String pFileName) {
+        if (files != null) {
+            files.remove(pFileName);
+        }    
+    }    
+    
+
+    public char[] getContent(final String pFileName)
+    {
+        return (char[]) files.get(pFileName);
+    }
+
+    public String[] list() {
+        if (files == null) {
+            return new String[0];
+        }
+        return (String[]) files.keySet().toArray(new String[files.size()]);
+    }
+}

Propchange: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/readers/MemoryResourceReader.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java?rev=348812&r1=348811&r2=348812&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/FileResourceStore.java
Thu Nov 24 13:50:10 2005
@@ -22,6 +22,8 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
 import org.apache.commons.io.IOUtils;
 
 
@@ -87,10 +89,26 @@
         final String fileName = pResourceName.replace('.', File.separatorChar) + ".class";
         return new File(root, fileName);
     }
+
+    public String[] list() {
+        final List files = new ArrayList();
+        list(root, files);
+        return (String[]) files.toArray(new String[files.size()]);
+    }
+
+    private void list(final File pFile, final List pFiles) {
+        if (pFile.isDirectory()) {
+            final File[] directoryFiles = pFile.listFiles();
+            for (int i=0; i < directoryFiles.length; i++) {
+                list(directoryFiles[i], pFiles);
+            }
+        } else {
+            pFiles.add(pFile.getAbsolutePath().substring(root.getAbsolutePath().length()+1));
+        }
+    }
     
     public String toString() {
         return this.getClass().getName() + root.toString();
     }
 
-    
 }

Modified: jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java?rev=348812&r1=348811&r2=348812&view=diff
==============================================================================
--- jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
(original)
+++ jakarta/commons/sandbox/jci/trunk/src/java/org/apache/commons/jci/stores/MemoryResourceStore.java
Thu Nov 24 13:50:10 2005
@@ -15,9 +15,11 @@
  */
 package org.apache.commons.jci.stores;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -33,19 +35,33 @@
 	private final Map store = new HashMap();
 	
 	public byte[] read( final String resourceName ) {
-		return (byte[]) store.get(resourceName);
+		return (byte[]) store.get(resourceName.replace('.', '/') + ".class");
 	}
 
 	public void write( final String resourceName, final byte[] clazzData ) {
 		log.debug("storing resource " + resourceName + "(" + clazzData.length + ")");
-		store.put(resourceName, clazzData);
+		store.put(resourceName.replace('.', '/') + ".class", clazzData);
 	}
 	
     public void remove( final String resourceName ) {
         log.debug("removing resource " + resourceName);
-        store.remove(resourceName);
+        store.remove(resourceName.replace('.', '/') + ".class");
     }
 
+    public String[] list() {
+        if (store == null) {
+            return new String[0];
+        }
+        final List names = new ArrayList();
+        
+        for (final Iterator it = store.keySet().iterator(); it.hasNext();) {
+            final String name = (String) it.next();
+            names.add(name.replace('/', '.').substring(0, name.length()-6));
+        }
+
+        return (String[]) names.toArray(new String[store.size()]);
+    }
+    
     public String toString() {
         return this.getClass().getName() + store.toString();
     }



---------------------------------------------------------------------
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