Author: ruwan
Date: Mon Nov 27 04:53:36 2006
New Revision: 479609

URL: http://svn.apache.org/viewvc?view=rev&rev=479609
Log:
committing for chathura

Modified:
    
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/Registry.java
    
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java

Modified: 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/Registry.java
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/Registry.java?view=diff&rev=479609&r1=479608&r2=479609
==============================================================================
--- 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/Registry.java
 (original)
+++ 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/Registry.java
 Mon Nov 27 04:53:36 2006
@@ -60,6 +60,20 @@
     public void addConfigProperty(String name, String value);
 
     /**
+     * Returns the child elements of a given registry entry
+     * @param entry - parent registry entry
+     * @return Array of child registry entries of the given parent registry 
entry
+     */
+    public RegistryEntry[] getChildren(RegistryEntry entry);
+
+    /**
+     * Returns all decendant entries of the given registry entry
+     * @param entry - parent registry entry
+     * @return Array of decendant registry entries of the given registry entry
+     */
+    public RegistryEntry[] getDescendants(RegistryEntry entry);
+
+    /**
      * Get the name of this registry
      * @return name of the registry
      */

Modified: 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java
URL: 
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java?view=diff&rev=479609&r1=479608&r2=479609
==============================================================================
--- 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java
 (original)
+++ 
incubator/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/url/SimpleURLRegistry.java
 Mon Nov 27 04:53:36 2006
@@ -31,8 +31,9 @@
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import java.io.IOException;
+import java.io.*;
 import java.net.*;
+import java.util.ArrayList;
 
 /**
  * A Simple HTTP GET based registry which will work with a Web Server / WebDAV
@@ -44,6 +45,8 @@
 
     private static final Log log = LogFactory.getLog(SimpleURLRegistry.class);
 
+    private static final int MAX_KEYS = 200;
+
     public OMNode lookup(String key) {
 
         log.info("==> Repository fetch of resource with key : " + key);
@@ -98,6 +101,27 @@
         return null;
     }
 
+    public void addConfigProperty(String name, String value) {
+
+        if(name.equals("root")) {
+
+            // if the root is folder, it should always end with '/'
+            // therefore, property keys do not have to begin with '/', which 
could be misleading
+            try {
+                URL url = new URL(value);
+                if(url.getProtocol().equals("file")) {
+                    if(!value.endsWith("/")) {
+                        value = value + "/";
+                    }
+                }
+            } catch (MalformedURLException e) {
+                // don't do any thing if this is not a valid URL
+            }
+        }
+
+        super.addConfigProperty(name, value);
+    }
+
     public String getRoot() {
         String root = (String) properties.get("root");
         if (root == null) {
@@ -110,6 +134,99 @@
     public long getCachableDuration() {
         String cachableDuration = (String) properties.get("cachableDuration");
         return cachableDuration == null ? 1500 : 
Long.parseLong(cachableDuration);
+    }
+
+    public RegistryEntry[] getChildren(RegistryEntry entry) {
+
+        try {
+            URL url;
+            if(entry == null) {
+                URLRegistryEntry urlEntry = new URLRegistryEntry();
+                urlEntry.setKey("");
+                entry = urlEntry;
+            }
+
+            url = new URL(getRoot() + entry.getKey());
+
+            if(url.getProtocol().equals("file")) {
+
+                File file = new File(url.getFile());
+                if(file.isDirectory() == false) {
+                    return null;
+                }
+
+                InputStream inStream = null;
+                try {
+                    inStream = (InputStream) url.getContent();
+
+                    BufferedReader reader = new BufferedReader(new 
InputStreamReader(inStream));
+                    ArrayList entryList = new ArrayList();
+                    String key = "";
+                    while((key=reader.readLine()) != null) {
+                        URLRegistryEntry registryEntry = new 
URLRegistryEntry();
+                        registryEntry.setKey(entry.getKey() + "/" + key);
+                        entryList.add(registryEntry);
+                    }
+
+                    RegistryEntry[] entries = new 
RegistryEntry[entryList.size()];
+                    for(int i=0; i<entryList.size(); i++) {
+                        entries[i] = (RegistryEntry) entryList.get(i);
+                    }
+                    return entries;
+
+                } catch(Exception e) {
+                    throw new SynapseException("Error in reading the URL.");
+                }
+
+            } else {
+                throw new SynapseException("Invalid protocol.");
+            }
+
+        } catch (MalformedURLException e) {
+            handleException("Invalid URL reference " + getRoot() + 
entry.getKey(), e);
+        }
+
+        return null;
+    }
+
+    public RegistryEntry[] getDescendants(RegistryEntry entry) {
+
+        ArrayList list = new ArrayList();
+        RegistryEntry[] entries = getChildren(entry);
+        if(entries != null) {
+            for(int i=0; i<entries.length; i++) {
+
+                if(list.size() > MAX_KEYS) {
+                    break;
+                }
+
+                fillDescendants(entries[i], list);
+            }
+        }
+
+        RegistryEntry[] descendants = new RegistryEntry[list.size()];
+        for(int i=0; i<list.size(); i++) {
+            descendants[i] = (RegistryEntry) list.get(i);
+        }
+
+        return descendants;
+    }
+
+    private void fillDescendants(RegistryEntry parent, ArrayList list) {
+
+        RegistryEntry[] entries = getChildren(parent);
+        if(entries != null) {
+            for(int i=0; i<entries.length; i++) {
+
+                if(list.size() > MAX_KEYS) {
+                    break;
+                }
+
+                fillDescendants(entries[i], list);
+            }
+        } else {
+            list.add(parent);
+        }
     }
 
     private void handleException(String msg, Exception e) {



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to