Author: ruwan
Date: Mon Apr 28 22:34:30 2008
New Revision: 16307

Log:

Fixing the Registry API, to incoporate the changes of WSO2 Registry


Modified:
   
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/ESBRegistry.java
   
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/RegistryAdapterFactory.java
   
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/WSO2RegistryAdapter.java

Modified: 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/ESBRegistry.java
==============================================================================
--- 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/ESBRegistry.java
    (original)
+++ 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/ESBRegistry.java
    Mon Apr 28 22:34:30 2008
@@ -53,7 +53,7 @@
  * Registry implementation for ESB. This assumes that registry resources can 
be accessed using file
  * system or http. Registry meta data are accessed using web services.
  */
-public class ESBRegistry extends AbstractRegistry implements Registry {
+public class ESBRegistry extends AbstractRegistry {
 
     public static final int FILE = 100;
     public static final int HTTP = 101;

Modified: 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/RegistryAdapterFactory.java
==============================================================================
--- 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/RegistryAdapterFactory.java
 (original)
+++ 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/RegistryAdapterFactory.java
 Mon Apr 28 22:34:30 2008
@@ -26,16 +26,11 @@
 import org.wso2.esb.ServiceBusConfiguration;
 import org.wso2.esb.ServiceBusConstants;
 import org.wso2.esb.ServiceBusException;
-import org.wso2.registry.RegistryConstants;
 import org.wso2.registry.RegistryException;
 import org.wso2.registry.app.RemoteRegistry;
-import org.wso2.registry.jdbc.InMemoryJDBCRegistry;
-import org.wso2.registry.jdbc.JDBCRegistry;
-import org.wso2.registry.jdbc.realm.InMemoryRegistryRealm;
-import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.jdbc.EmbeddedRegistry;
+import org.wso2.registry.jdbc.InMemoryEmbeddedRegistry;
 import org.wso2.registry.jdbc.utils.RegistryDataSource;
-import org.wso2.registry.secure.SecureRegistry;
-import org.wso2.registry.users.UserRealm;
 
 import java.io.File;
 import java.net.MalformedURLException;
@@ -143,17 +138,14 @@
 
         try {
 
-            InMemoryRegistryRealm inMemoryRegistryRealm = new 
InMemoryRegistryRealm();
-            InMemoryJDBCRegistry inMemoryRegsitry = new 
InMemoryJDBCRegistry(inMemoryRegistryRealm);
-
-            return new SecureRegistry(RegistryConstants.ADMIN_USER,
-                    RegistryConstants.ADMIN_PASSWORD,
-                    inMemoryRegsitry, inMemoryRegistryRealm);
+            return new InMemoryEmbeddedRegistry().getSystemRegistry();
 
         } catch (RegistryException e) {
             handleException("Error when initiating a in memory registry", e);
         }
-        throw new ServiceBusException("InMemory registry cannot be null");
+
+        // never executes - just to make the compiler happy
+        return null;
     }
 
     /**
@@ -162,7 +154,8 @@
      * @param esbConfiguration ESB configuration instance to be used to get 
configuration data
      * @return A JDBC registry instance
      */
-    private static org.wso2.registry.Registry 
createJDBCRegistry(ServiceBusConfiguration esbConfiguration) {
+    private static org.wso2.registry.Registry createJDBCRegistry(
+        ServiceBusConfiguration esbConfiguration) {
 
         String registryDriverClass = esbConfiguration
                 .getFirstProperty
@@ -194,12 +187,8 @@
             RegistryDataSource dataSource = new RegistryDataSource(
                     registryUrl, registryDriverClass, registryUsername, 
registryPassword);
 
-            UserRealm realm = new RegistryRealm(dataSource);
-
-            JDBCRegistry jdbcRegistry = new JDBCRegistry(dataSource, realm);
-
-            return new SecureRegistry(RegistryConstants.ADMIN_USER,
-                    RegistryConstants.ADMIN_PASSWORD, jdbcRegistry, realm);
+            EmbeddedRegistry embeddedRegistry = new 
EmbeddedRegistry(dataSource);
+            return embeddedRegistry.getSystemRegistry();
 
         } catch (RegistryException e) {
             handleException("Error when initiating a JDBC registry", e);
@@ -213,7 +202,8 @@
      * @param esbConfiguration ESB configuration instance to be used to get 
configuration data
      * @return A remote registry instance
      */
-    private static org.wso2.registry.Registry 
createRemoteRegistry(ServiceBusConfiguration esbConfiguration) {
+    private static org.wso2.registry.Registry createRemoteRegistry(
+        ServiceBusConfiguration esbConfiguration) {
 
         String registryUrl = esbConfiguration
                 .getFirstProperty(

Modified: 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/WSO2RegistryAdapter.java
==============================================================================
--- 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/WSO2RegistryAdapter.java
    (original)
+++ 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/registry/WSO2RegistryAdapter.java
    Mon Apr 28 22:34:30 2008
@@ -18,28 +18,27 @@
 */
 package org.wso2.esb.registry;
 
-import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
-import org.apache.synapse.util.SynapseBinaryDataSource;
 import org.apache.synapse.config.Entry;
 import org.apache.synapse.registry.AbstractRegistry;
-import org.apache.synapse.registry.Registry;
 import org.apache.synapse.registry.RegistryEntry;
 import org.apache.synapse.registry.RegistryEntryImpl;
+import org.apache.synapse.util.SynapseBinaryDataSource;
 import org.wso2.esb.ServiceBusConstants;
 import org.wso2.registry.*;
 import org.wso2.registry.utils.RegistryClientUtils;
 
+import javax.activation.DataHandler;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import javax.activation.DataHandler;
 import java.io.*;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -50,7 +49,7 @@
 /**
  * This adopts the WSO2 registry as a synapse registry.
  */
-public class WSO2RegistryAdapter extends AbstractRegistry implements Registry {
+public class WSO2RegistryAdapter extends AbstractRegistry {
 
     private static final Log log = 
LogFactory.getLog(WSO2RegistryAdapter.class);
 
@@ -220,7 +219,7 @@
                 try {
                     expirationTime = Long.parseLong(expiration);
                 } catch (NumberFormatException e) {
-
+                    handleException("Couldn't pass the expiry time as a long", 
e);
                 }
             }
 
@@ -234,7 +233,7 @@
                     try {
                         cacheTime = Long.parseLong(cachableDuration);
                     } catch (NumberFormatException e) {
-
+                        handleException("Couldn't pass the cachableDuration as 
a long", e);
                     }
                     entry.setCachableDuration(cacheTime);
                 }
@@ -274,11 +273,11 @@
 
             CollectionImpl collection = (CollectionImpl) resource;
             String[] children = collection.getChildren();
-            List entryList = new ArrayList();
+            List<RegistryEntry> entryList = new ArrayList<RegistryEntry>();
 
-            for (int i = 0; i < children.length; i++) {
+            for (String child : children) {
 
-                String key = removePathSeparator(children[i]);
+                String key = removePathSeparator(child);
 
                 Resource childResource = getResource(key);
                 if (childResource == null) {
@@ -297,7 +296,7 @@
                 entryList.add(registryEntryEmbedded);
             }
 
-            return (RegistryEntry[]) entryList.toArray(new 
RegistryEntry[entryList.size()]);
+            return entryList.toArray(new RegistryEntry[entryList.size()]);
         } else {
             ((RegistryEntryImpl) entry).setType(ServiceBusConstants.file);
             return new RegistryEntry[]{entry};
@@ -313,22 +312,21 @@
      */
     public RegistryEntry[] getDescendants(RegistryEntry entry) {
 
-        ArrayList list = new ArrayList();
+        ArrayList<RegistryEntry> list = new ArrayList<RegistryEntry>();
         RegistryEntry[] entries = getChildren(entry);
+        
         if (entries != null) {
-            for (int i = 0; i < entries.length; i++) {
-
+            for (RegistryEntry entry1 : entries) {
                 if (list.size() > MAX_KEYS) {
                     break;
                 }
-
-                fillDescendants(entries[i], list);
+                fillDescendants(entry1, list);
             }
         }
 
         RegistryEntry[] descendants = new RegistryEntry[list.size()];
         for (int i = 0; i < list.size(); i++) {
-            descendants[i] = (RegistryEntry) list.get(i);
+            descendants[i] = list.get(i);
         }
 
         return descendants;
@@ -391,7 +389,7 @@
         //Getting cache time and expiration time from parent ,
         //as child should inherit parents properties
         long cacheTime = getCachableDuration(); // roots cache time
-        long expirationTime = 0;
+        long expirationTime;
 
         if (parent != null) {
 
@@ -400,16 +398,7 @@
                 try {
                     cacheTime = Long.parseLong(cachableDuration);
                 } catch (NumberFormatException e) {
-
-                }
-            }
-
-            String expiration = parent.getProperty(EXPIRY_TIME);
-            if (expiration != null) {
-                try {
-                    expirationTime = Long.parseLong(expiration);
-                } catch (NumberFormatException e) {
-
+                    handleException("Couldn't pass the cachableDuration as a 
long", e);                    
                 }
             }
         }
@@ -544,36 +533,34 @@
         }
         if (file.isDirectory()) {
             String[] children = file.list();
-            for (int i = 0; i < children.length; i++) {
+            for (String strChild : children) {
 
                 try {
-                    File child = new File(file, children[i]);
+                    File child = new File(file, strChild);
                     String path = removePathSeparator(toPath) + "/" + 
child.getName();
 
                     if (!registry.resourceExists(path)) {
                         RegistryClientUtils.importToRegistry(child,
-                                toPath, registry);
+                            toPath, registry);
                     }
 
                 } catch (RegistryException e) {
                     handleException("Error when importing resources in " +
-                            "the path : " + file.getPath(), e);
+                        "the path : " + file.getPath(), e);
                 }
             }
         }
     }
 
-    private void fillDescendants(RegistryEntry parent, ArrayList list) {
+    private void fillDescendants(RegistryEntry parent, 
ArrayList<RegistryEntry> list) {
 
         RegistryEntry[] entries = getChildren(parent);
         if (entries != null) {
-            for (int i = 0; i < entries.length; i++) {
-
+            for (RegistryEntry entry : entries) {
                 if (list.size() > MAX_KEYS) {
                     break;
                 }
-
-                fillDescendants(entries[i], list);
+                fillDescendants(entry, list);
             }
         } else {
             list.add(parent);

_______________________________________________
Esb-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev

Reply via email to