Author: chathura
Date: Wed Jan 16 01:30:22 2008
New Revision: 12329

Log:


Refactored the URLHandler interface and all implementation classes.



Modified:
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
       (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentCollectionURLHandler.java
       Wed Jan 16 01:30:22 2008
@@ -37,24 +37,24 @@
         super(dataSource);
     }
 
-    public boolean handleURL(String url, Resource resource) throws 
RegistryException {
+    public Resource handleURL(String url) throws RegistryException {
 
         String[] parts = url.split(";");
 
         if (parts.length != 2) {
-            return false;
+            return null;
         }
 
         if (parts[0].length() == 0) {
-            return false;
+            return null;
         }
 
         if (!parts[1].equals("comments")) {
-            return false;
+            return null;
         }
 
         if (parts[1].length() != "comments".length()) {
-            return false;
+            return null;
         }
 
         String resourcePath = parts[0];
@@ -69,6 +69,7 @@
         CommentsDAO commentsDAO = new CommentsDAO();
 
         try {
+            Resource resource = new Resource();
             resource.setPath(url);
             resource.setDirectory(true);
 
@@ -82,7 +83,7 @@
                     (String[])commentPaths.toArray(new 
String[commentPaths.size()]);
             resource.setContent(commentsContent);
 
-            return true;
+            return resource;
 
         } catch (SQLException e) {
             String msg = "Failed to get comments for resource: " +

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
 (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/CommentURLHandler.java
 Wed Jan 16 01:30:22 2008
@@ -42,28 +42,27 @@
      * Accepts URL in the form <path>?comment<comment-id>
      *
      * @param url
-     * @param resource
      * @return
      */
-    public boolean handleURL(String url, Resource resource) throws 
RegistryException {
+    public Resource handleURL(String url) throws RegistryException {
 
         String[] parts = url.split(";");
 
         if (parts.length != 2) {
-            return false;
+            return null;
         }
 
         if (parts[0].length() == 0) {
-            return false;
+            return null;
         }
 
         if (!parts[1].startsWith("comments:")) {
-            return false;
+            return null;
         }
 
         String commentID = parts[1].substring("comments:".length());
         if (!(commentID.length() > 0)) {
-            return false;
+            return null;
         }
 
         long cID ;
@@ -74,7 +73,7 @@
             // note that this might not be an exceptional scenario. there 
could be a different URL
             // form, which contains strings after "comment".
             // it is just that it is not the URL we expect here
-            return false;
+            return null;
         }
 
         Connection conn;
@@ -110,6 +109,7 @@
             throw new RegistryException(msg);
         }
 
+        Resource resource = new Resource();
         resource.setPath(url);
         resource.setMediaType(RegistryConstants.COMMENT_MEDIA_TYPE);
         resource.setContent(comment.getText());
@@ -117,6 +117,6 @@
         resource.setCreatedTime(comment.getTime());
         resource.setProperty("resourcePath", resourcePath);
 
-        return true;
+        return resource;
     }
 }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
  (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingURLHandler.java
  Wed Jan 16 01:30:22 2008
@@ -36,21 +36,21 @@
         super(dataSource);
     }
 
-    public boolean handleURL(String url, Resource resource) throws 
RegistryException {
+    public Resource handleURL(String url) throws RegistryException {
 
         String[] parts = url.split(";");
 
         if (parts.length != 2) {
-            return false;
+            return null;
         }
 
         if (parts[0].length() == 0) {
-            return false;
+            return null;
         }
 
         String[] details = parts[1].split(":");
         if (details.length != 2 || !details[0].equals("ratings") || 
details[1].length() == 0) {
-            return false;
+            return null;
         }
 
         String resourcePath = parts[0];
@@ -69,6 +69,7 @@
             int rating = ratingsDAO.getRating(resourcePath, ratedUserName, 
conn);
             Date ratedTime = ratingsDAO.getRatedTime(resourcePath, 
ratedUserName, conn);
 
+            Resource resource = new Resource();
             resource.setMediaType(RegistryConstants.RATING_MEDIA_TYPE);
             resource.setContent(new Integer(rating));
             resource.setAuthorUserName(ratedUserName);
@@ -76,6 +77,8 @@
             resource.setCreatedTime(ratedTime);
             resource.setProperty("resourcePath", resourcePath);
 
+            return resource;
+
         } catch (SQLException e) {
             String msg = "Could not get the rating for resource at " + 
resourcePath +
                          ". Caused by: " + e.getMessage();
@@ -89,7 +92,5 @@
                 } catch (SQLException ignore) {}
             }
         }
-
-        return true;
     }
 }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
       (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/RatingsCollectionURLHandler.java
       Wed Jan 16 01:30:22 2008
@@ -36,24 +36,24 @@
         super(dataSource);
     }
 
-    public boolean handleURL(String url, Resource resource) throws 
RegistryException {
+    public Resource handleURL(String url) throws RegistryException {
 
         String[] parts = url.split(";");
 
         if (parts.length != 2) {
-            return false;
+            return null;
         }
 
         if (parts[0].length() == 0) {
-            return false;
+            return null;
         }
 
         if (!parts[1].equals("ratings")) {
-            return false;
+            return null;
         }
 
         if (parts[1].length() != "ratings".length()) {
-            return false;
+            return null;
         }
 
         String resourcePath = parts[0];
@@ -68,6 +68,7 @@
         RatingsDAO ratingsDAO = new RatingsDAO();
 
         try {
+            Resource resource = new Resource();
             resource.setPath(url);
             resource.setDirectory(true);
 
@@ -82,7 +83,7 @@
                     (String[])ratingPaths.toArray(new 
String[ratingPaths.size()]);
             resource.setContent(ratingsContent);
 
-            return true;
+            return resource;
 
         } catch (SQLException e) {
             String msg = "Failed to get ratings for resource: " +

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
     (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/TagURLHandler.java
     Wed Jan 16 01:30:22 2008
@@ -36,26 +36,25 @@
      * Accepts the URLs in the form <path>;tags:<tag-name>:<user-name>
      *
      * @param url
-     * @param resource
      * @return
      * @throws RegistryException
      */
-    public boolean handleURL(String url, Resource resource) throws 
RegistryException {
+    public Resource handleURL(String url) throws RegistryException {
 
         String[] parts = url.split(";");
 
         if (parts.length != 2) {
-            return false;
+            return null;
         }
 
         if (parts[0].length() == 0) {
-            return false;
+            return null;
         }
 
         String[] queries = parts[1].split(":");
 
         if (queries.length != 3) {
-            return false;
+            return null;
         }
 
         String resourcePath = parts[0];
@@ -73,12 +72,15 @@
             TagsDAO tagsDAO = new TagsDAO();
             TaggingDO taggingDO = tagsDAO.getTagging(resourcePath, tagName, 
userName, conn);
 
+            Resource resource = new Resource();
             resource.setMediaType(RegistryConstants.TAG_MEDIA_TYPE);
             resource.setContent(taggingDO.getTagName());
             resource.setAuthorUserName(taggingDO.getTaggedUserName());
             resource.setCreatedTime(taggingDO.getTaggedTime());
             resource.setProperty("resourcePath", taggingDO.getResourcePath());
 
+            return resource;
+
         } catch (SQLException e) {
             String msg = "Could not get tagging. Caused by: " + e.getMessage();
             throw new RegistryException(msg, e);
@@ -90,7 +92,5 @@
 
             }
         }
-
-        return true;
     }
 }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
        (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandler.java
        Wed Jan 16 01:30:22 2008
@@ -41,5 +41,18 @@
         this.dataSource = dataSource;
     }
 
-    public abstract boolean handleURL(String url, Resource resource) throws 
RegistryException;
+    /**
+     * Determine if the given url can be handled. If yes, process the request 
and return the
+     * resulting resource. Further processing of the resource is terminated if 
a resource is
+     * returned. If the given url cannot be handled return null, which causes 
other url
+     * handlers to process the request, or the request to be reached the media 
type handlers.
+     *
+     * @param url URL to process
+     * 
+     * @return Resource instance if the URL can be processed. Null if the 
request cannot be
+     * processed.
+     *
+     * @throws RegistryException
+     */
+    public abstract Resource handleURL(String url) throws RegistryException;
 }

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
 (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/urlhandlers/URLHandlerManager.java
 Wed Jan 16 01:30:22 2008
@@ -40,13 +40,13 @@
     public Resource handleURL(String url)
             throws RegistryException {
 
-        Resource resource = new Resource();
+        Resource resource;
 
         Iterator i = urlHandlers.iterator();
         while (i.hasNext()) {
             URLHandler urlHandler = (URLHandler)i.next();
 
-            if (urlHandler.handleURL(url, resource)) {
+            if ((resource = urlHandler.handleURL(url)) != null) {
                 return resource;
             }
         }

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to