[Registry-dev] svn commit r16820 - in trunk/registry/modules/core/src: main/java/org/wso2/registry/app main/java/org/wso2/registry/jdbc/filecache test/java/org/wso2/registry/app

svn at wso2.org svn at wso2.org
Sun May 11 22:02:24 PDT 2008


Author: glen
Date: Sun May 11 22:02:24 2008
New Revision: 16820

Log:
* Improve APP property handling (APPbasedPropertyTest now works)

* Little code cleanup in FileManager

Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Property.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyValue.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/filecache/FileManager.java
   trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPbasedPropertyTest.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Property.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Property.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/Property.java	Sun May 11 22:02:24 2008
@@ -23,6 +23,8 @@
 import org.apache.abdera.model.ExtensibleElementWrapper;
 
 import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.Iterator;
 
 public class Property extends ExtensibleElementWrapper {
 
@@ -34,8 +36,11 @@
         super(factory, qname);
     }
 
-    public void setProperty(PropertyName propertyName, PropertyValue propertyValue) {
+    public void addName(PropertyName propertyName) {
         addExtension(propertyName);
+    }
+
+    public void addValue(PropertyValue propertyValue) {
         addExtension(propertyValue);
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyValue.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyValue.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/PropertyValue.java	Sun May 11 22:02:24 2008
@@ -26,6 +26,8 @@
 
 
 public class PropertyValue extends ElementWrapper {
+    private static final QName XSI_NIL = new QName("http://www.w3.org/2001/XMLSchema-instance",
+                                                   "nil", "xsi");
 
     public PropertyValue(Element internal) {
         super(internal);
@@ -36,10 +38,17 @@
     }
 
     public String getPropertyValue() {
+        String nil = getAttributeValue(XSI_NIL);
+        if (nil != null && nil.equals("true")) {
+            return null;
+        }
         return getText();
     }
 
     public void setPropertyValue(String propertyValue) {
+        if (propertyValue == null) {
+            setAttributeValue(XSI_NIL, "true");
+        }
         setText(propertyValue);
     }
 

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java	Sun May 11 22:02:24 2008
@@ -362,12 +362,11 @@
             for (Object aPropertyList : propertyList) {
                 Property property = (Property)aPropertyList;
                 PropertyName pn = property.getExtension(PropertyExtensionFactory.PROPERTY_NAME);
-                PropertyValue pv = property.getExtension(PropertyExtensionFactory.PROPERTY_VALUE);
-                String value = pv.getText();
-                List list =  decodeMultivaluedProperty(value);
-                for (Object aList : list) {
-                    String stringValue = (String)aList;
-                    resource.addProperty(pn.getText(), stringValue);
+                List<PropertyValue> pv =
+                        property.getExtensions(PropertyExtensionFactory.PROPERTY_VALUE);
+                String propertyName = pn.getText();
+                for (PropertyValue valueElement : pv) {
+                    resource.addProperty(propertyName, valueElement.getPropertyValue());
                 }
             }
         }
@@ -398,14 +397,15 @@
                 PropertyName pn = factory.newExtensionElement(
                         PropertyExtensionFactory.PROPERTY_NAME);
                 pn.setPropertyName(key);
-                PropertyValue pv = factory.newExtensionElement(
-                        PropertyExtensionFactory.PROPERTY_VALUE);
+                property.addName(pn);
                 Object valueList = properties.get(key);
-                String propertyValue ="" ;
                 if (valueList instanceof List) {
-                    propertyValue = encodeMultivaluedProperty((List)valueList, propertyValue);
-                    pv.setPropertyValue(propertyValue);
-                    property.setProperty(pn, pv);
+                    for (String value : (List<String>)valueList) {
+                        PropertyValue pv = factory.newExtensionElement(
+                                PropertyExtensionFactory.PROPERTY_VALUE);
+                        pv.setPropertyValue(value);
+                        property.addValue(pv);
+                    }
                     propertyElement.setProperty(property);
                 }
             }
@@ -413,26 +413,6 @@
         }
     }
 
-    private static String encodeMultivaluedProperty(List valueList, String propertyValue) {
-        for (Object aValueList : valueList) {
-            String value = (String)aValueList;
-            if ("".equals(propertyValue)) {
-                propertyValue = value;
-            } else {
-                propertyValue = propertyValue + "|" + value;
-            }
-        }
-        return propertyValue;
-    }
-
-    public static List decodeMultivaluedProperty(String propertyValue) {
-        String values [] = propertyValue.split("\\|");
-        List list = new ArrayList();
-        list.addAll(Arrays.asList(values));
-        return list;
-    }
-
-
     public String importResource(String suggestedPath, String sourceURL, Resource metadata)
             throws RegistryException {
         AbderaClient abderaClient = new AbderaClient(abdera);

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/filecache/FileManager.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/filecache/FileManager.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/filecache/FileManager.java	Sun May 11 22:02:24 2008
@@ -16,16 +16,14 @@
 
 package org.wso2.registry.jdbc.filecache;
 
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.jdbc.filecache.FileData;
-import org.wso2.registry.jdbc.filecache.RegistryFileInputStream;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.wso2.registry.RegistryException;
 
 import java.io.*;
-import java.util.Map;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Timer;
 
 public class FileManager {
@@ -48,12 +46,7 @@
     }
 
     public static boolean hasFileBasedContent(String contentID) {
-
-        if (fileDataMap.containsKey(contentID)) {
-            return true;
-        }
-
-        return false;
+        return fileDataMap.containsKey(contentID);
     }
 
     public static InputStream getFileBasedInputStream(String contentID) throws RegistryException {

Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPbasedPropertyTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPbasedPropertyTest.java	(original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPbasedPropertyTest.java	Sun May 11 22:02:24 2008
@@ -27,7 +27,7 @@
         try {
             if (registry == null) {
                 server.start();
-                registry = new RemoteRegistry(new URL("http://localhost:8081/wso2registry"),
+                registry = new RemoteRegistry(new URL("http://localhost:8082/wso2registry"),
                                               "admin", "admin");
             }
         } catch (Exception e) {



More information about the Registry-dev mailing list