[Registry-dev] svn commit r14784 - in trunk/registry/modules/core/src/main/java/org/wso2/registry: . app config jdbc jdbc/handlers jdbc/handlers/filters lifecycle secure users/def utils

svn at wso2.org svn at wso2.org
Thu Mar 13 08:24:25 PDT 2008


Author: glen
Date: Thu Mar 13 08:24:15 2008
New Revision: 14784

Log:

Work in progress - still needs some cleanup and tests.

* Refactor/simplify initial Lifecycle implementation to match email discussion.  DefaultLifecycle still does the same thing, but with a more general architecture.  Allow individual Lifecycles to manage their own states instead of having only a "current" state, and allow custom actions which are interpreted by Lifecycles.

* Code style fixes

* Start refactor for Filter (no real changes yet except introducing bit-fields for method)

Removed:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/LifecycleComparator.java
Modified:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/RequestContext.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/MediaTypeMatcher.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/DefaultLifecycle.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/Lifecycle.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java	Thu Mar 13 08:24:15 2008
@@ -76,36 +76,34 @@
 
     /**
      * Adds a dependency stating that the resource at "dependentPath" depends on the resource at
-     * "dependencyPath". Paths may be the resource paths of the current versions or paths of the
-     * old versions. If a path refers to the current version, it should contain the path in the
-     * form /c1/c2/r1. If it refers to an old version, it should be in the form /c1/c2/r1?v=2.
+     * "dependencyPath". Paths may be the resource paths of the current versions or paths of the old
+     * versions. If a path refers to the current version, it should contain the path in the form
+     * /c1/c2/r1. If it refers to an old version, it should be in the form /c1/c2/r1?v=2.
      *
-     * @param dependentPath Path of the dependent resource
+     * @param dependentPath   Path of the dependent resource
      * @param dependencyPaths Paths of dependency resources
      * @throws RegistryException Depends on the implementation
      */
     void addDependencies(String dependentPath, String[] dependencyPaths) throws RegistryException;
 
     /**
-     * Get all dependencies of the given resource. This is a chain of dependencies starting from
-     * the given resource. This is useful to analyse how changes to other resources would affect
-     * the given resource.
+     * Get all dependencies of the given resource. This is a chain of dependencies starting from the
+     * given resource. This is useful to analyse how changes to other resources would affect the
+     * given resource.
      *
      * @param resourcePath Path of the resource to analyse dependencies. This can be a path of a
-     * current resource or an old verion of a resource.
-     *
+     *                     current resource or an old verion of a resource.
      * @return Chain of dependencies
      */
     DependencyChain[] getAllDependencies(String resourcePath) throws RegistryException;
 
     /**
-     * Get all dependents of the given resource. This is a chain of dependents starting from
-     * the given resource. This is useful to analyse how changes to the given resources would affect
+     * Get all dependents of the given resource. This is a chain of dependents starting from the
+     * given resource. This is useful to analyse how changes to the given resources would affect
      * other resources.
      *
      * @param resourcePath Path of the resource to analyse dependents. This can be a path of a
-     * current resource or an old verion of a resource.
-     *
+     *                     current resource or an old verion of a resource.
      * @return Chain of dependents
      */
     DependentChain[] getAllDependents(String resourcePath) throws RegistryException;
@@ -260,18 +258,24 @@
 
     /**
      * Associate a lifecycle into a resource.
-     * @param resourcePath : Path of the resource
-     * @param lifecycle : Name of the lifecycle
+     *
+     * @param resourcePath Path of the resource
+     * @param lifecycle    Name of the lifecycle
      * @throws RegistryException : If some thing went wrong while doing associating the phase
      */
-    void associateLifeCycle(String resourcePath ,
-                            String lifecycle) throws RegistryException ;
+    void associateLifeCycle(String resourcePath,
+                            String lifecycle) throws RegistryException;
 
     /**
      * This will change the current resource lifecycle state to the next state. By looking at the
      * order of the lifecycle internal logic has to decied where to go.
-     * @param resourcePath : path of the resource
-     * @throws RegistryException : If some thing went wrong while doing transition
+     *
+     * @param resourcePath  Path of the resource
+     * @param lifecycleName Name of the lifecycle
+     * @param action        Which action was selected - actions are lifecycle-specific
+     * @throws RegistryException If some thing went wrong while doing
+     *                      transition
      */
-    void lifeCycleTransition(String resourcePath)throws RegistryException ;
+    void lifeCycleTransition(String resourcePath, String lifecycleName, String action)
+            throws RegistryException;
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Resource.java	Thu Mar 13 08:24:15 2008
@@ -79,5 +79,5 @@
 
     Lifecycle[] getLifecycles();
 
-    Lifecycle getCurrentLifecycle();
+    Lifecycle getLifecycle(String name);
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/ResourceImpl.java	Thu Mar 13 08:24:15 2008
@@ -174,6 +174,11 @@
      */
     private VersionedResourceDAO resourceDAO;
 
+    /**
+     * Lifecycles (custom state machines) with which this Resource is associated
+     */
+    private Map <String, Lifecycle> lifecycles;
+
     public ResourceImpl() {
     }
 
@@ -476,14 +481,16 @@
         this.contentModified = contentModified;
     }
 
-
     public Lifecycle[] getLifecycles() {
+        if (lifecycles == null) return new Lifecycle[0];
+
         // all the lifecycle assigned to the resource
-        return new Lifecycle[0];
+        return (Lifecycle[])lifecycles.values().toArray();
     }
 
-    public Lifecycle getCurrentLifecycle() {
-        // Current Lifecycle
-        return null;
+    public Lifecycle getLifecycle(String name) {
+        if (lifecycles == null) return null;
+
+        return lifecycles.get(name);
     }
 }

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	Thu Mar 13 08:24:15 2008
@@ -296,8 +296,8 @@
                 PropertyValue pv = property.getExtension(PropertyExtensionFactory.PROPERTY_VALUE);
                 String value = pv.getText();
                 List list =  decodeMultivaluedProperty(value);
-                for (int i = 0; i < list.size(); i++) {
-                    String stringValue = (String)list.get(i);
+                for (Object aList : list) {
+                    String stringValue = (String)aList;
                     resource.addProperty(pn.getText(), stringValue);
                 }
             }
@@ -346,8 +346,8 @@
     }
 
     private static String encodeMultivaluedProperty(List valueList, String propertyValue) {
-        for (int i = 0; i < valueList.size(); i++) {
-            String value = (String) valueList.get(i);
+        for (Object aValueList : valueList) {
+            String value = (String)aValueList;
             if ("".equals(propertyValue)) {
                 propertyValue = value;
             } else {
@@ -360,10 +360,7 @@
     public static List decodeMultivaluedProperty(String propertyValue) {
         String values [] = propertyValue.split("\\|");
         List list = new ArrayList();
-        for (int i = 0; i < values.length; i++) {
-            String value = values[i];
-            list.add(value);
-        }
+        list.addAll(Arrays.asList(values));
         return list;
     }
 
@@ -847,7 +844,7 @@
         throw new UnsupportedOperationException();
     }
 
-    public void lifeCycleTransition(String resourcePath) throws RegistryException {
+    public void lifeCycleTransition(String resourcePath, String lifecycleName, String action) throws RegistryException {
         throw new UnsupportedOperationException();
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java	Thu Mar 13 08:24:15 2008
@@ -195,7 +195,6 @@
                         try {
                             Class handlerClass = Class.forName(clazz);
                             Lifecycle lifecycleInstance = (Lifecycle) handlerClass.newInstance();
-                            lifecycleInstance.setLocation(Integer.parseInt(order));
                             lifecycleInstance.setName(name);
                             registryContext.addLifecycle(lifecycleInstance);
                         } catch (Exception e) {

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java	Thu Mar 13 08:24:15 2008
@@ -21,26 +21,26 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.wso2.registry.*;
 import org.wso2.registry.Collection;
-import org.wso2.registry.lifecycle.Lifecycle;
+import org.wso2.registry.*;
 import org.wso2.registry.config.RegistryContext;
 import org.wso2.registry.exceptions.ResourceNotFoundException;
 import org.wso2.registry.i18n.Messages;
 import org.wso2.registry.jdbc.dao.*;
-import org.wso2.registry.jdbc.queries.QueryProcessorManager;
-import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.jdbc.handlers.Handler;
 import org.wso2.registry.jdbc.handlers.HandlerManager;
 import org.wso2.registry.jdbc.handlers.RequestContext;
-import org.wso2.registry.jdbc.handlers.Handler;
+import org.wso2.registry.jdbc.handlers.builtin.*;
+import org.wso2.registry.jdbc.handlers.filters.Filter;
 import org.wso2.registry.jdbc.handlers.filters.MediaTypeMatcher;
 import org.wso2.registry.jdbc.handlers.filters.URLMatcher;
-import org.wso2.registry.jdbc.handlers.filters.Filter;
-import org.wso2.registry.jdbc.handlers.builtin.*;
+import org.wso2.registry.jdbc.queries.QueryProcessorManager;
+import org.wso2.registry.jdbc.realm.RegistryRealm;
+import org.wso2.registry.lifecycle.Lifecycle;
 import org.wso2.registry.users.UserRealm;
 import org.wso2.registry.utils.AuthorizationUtil;
-import org.wso2.registry.utils.VersionedPath;
 import org.wso2.registry.utils.RegistryUtils;
+import org.wso2.registry.utils.VersionedPath;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
@@ -155,8 +155,8 @@
                 resourceDAO.add(root, conn);
 
                 AuthorizationUtil.setDefaultAuthorizations(defaultRealm,
-                        RegistryConstants.ROOT_PATH,
-                        RegistryConstants.SYSTEM_USER);
+                                                           RegistryConstants.ROOT_PATH,
+                                                           RegistryConstants.SYSTEM_USER);
 
                 root = resourceDAO.getLatestVersion(RegistryConstants.ROOT_PATH, conn);
                 root.setLastUpdaterUserName(RegistryConstants.SYSTEM_USER);
@@ -219,7 +219,7 @@
 
         // check if this path refers to a resource referred by a URL query (e.g. comment)
 
-        RequestContext requestContext = new RequestContext();
+        RequestContext requestContext = new RequestContext(this);
         requestContext.setResourcePath(path);
 
         Resource resource = handlerManager.get(requestContext);
@@ -287,7 +287,7 @@
             throws RegistryException {
         suggestedPath = preparePath(suggestedPath);
 
-        RequestContext requestContext = new RequestContext();
+        RequestContext requestContext = new RequestContext(this);
         requestContext.setResourcePath(suggestedPath);
         requestContext.setResource(resource);
 
@@ -351,11 +351,11 @@
 
         suggestedPath = preparePath(suggestedPath);
 
-        RequestContext importChildContext = new RequestContext();
+        RequestContext importChildContext = new RequestContext(this);
         importChildContext.setResourcePath(RegistryUtils.getParentPath(suggestedPath));
         handlerManager.importChild(importChildContext);
 
-        RequestContext requestContext = new RequestContext();
+        RequestContext requestContext = new RequestContext(this);
         requestContext.setResourcePath(suggestedPath);
         requestContext.setSourceURL(sourceURL);
         requestContext.setResource(metadata);
@@ -409,9 +409,9 @@
     public String rename(String currentPath, String newPath) throws RegistryException {
 
         if (currentPath == null || currentPath.length() == 0 ||
-                newPath == null || newPath.length() == 0) {
+            newPath == null || newPath.length() == 0) {
             String msg = "Invlaid resource paths. Current path: " +
-                    currentPath + ". New path: " + newPath;
+                         currentPath + ". New path: " + newPath;
             throw new RegistryException(msg);
         }
 
@@ -433,18 +433,18 @@
                     long resourceID = resourceDAO.getResourceID(currentPath, conn);
 
                     resourceDAO.renameResource(currentPath,
-                            newPath,
-                            getConnection(),
-                            User.getCurrentUser(),
-                            defaultRealm,
-                            this);
+                                               newPath,
+                                               getConnection(),
+                                               User.getCurrentUser(),
+                                               defaultRealm,
+                                               this);
 
                     logsDAO.addLog(resourceID, userID, LogEntry.RENAME, currentPath, conn);
 
                 } catch (Exception e) {
 
                     String msg = "Failed to rename the resource: " +
-                            currentPath + " to the name: " + newPath;
+                                 currentPath + " to the name: " + newPath;
                     log.error(msg, e);
                     throw new RegistryException(msg, e);
 
@@ -476,7 +476,7 @@
 
         path = preparePath(path);
 
-        RequestContext requestContext = new RequestContext();
+        RequestContext requestContext = new RequestContext(this);
         requestContext.setResourcePath(path);
 
         handlerManager.delete(requestContext);
@@ -484,7 +484,7 @@
         //if (!urlHandlerManager.delete(path)) {
         //    mediaTypeManager.delete(path);
         //}
-        
+
         if (!requestContext.isProcessingComplete()) {
             repository.delete(path);
         }
@@ -914,7 +914,7 @@
         } catch (Exception e) {
 
             String msg = "Could not remove the tag: " + tag + " from the resource at path: " +
-                    path + ".";
+                         path + ".";
             log.error(msg, e);
 
             try {
@@ -1070,13 +1070,13 @@
                 if (ratingsDAO.ratingExist(resource.getId(), userID, conn)) {
                     ratingsDAO.updateRating(resource.getId(), userID, rating, conn);
                     log.info("Updated the rating on the resource " +
-                            resourcePath + " by user " + userID);
+                             resourcePath + " by user " + userID);
                 } else {
                     ratingsDAO.addRating(resource.getId(), userID, rating, conn);
                 }
 
                 logsDAO.addLog(resource.getId(),
-                        userID, LogEntry.RATING, Integer.toString(rating), conn);
+                               userID, LogEntry.RATING, Integer.toString(rating), conn);
 
             } else {
                 String msg = Messages.getMessage("rate.on.null.artfact", resourcePath);
@@ -1158,7 +1158,7 @@
         } catch (SQLException e) {
 
             String msg = "Could not get the rating of the resource " + path +
-                    " given by the user " + userName + ". Caused by: " + e.getMessage();
+                         " given by the user " + userName + ". Caused by: " + e.getMessage();
             log.error(msg, e);
             throw new RegistryException(msg, e);
 
@@ -1313,47 +1313,48 @@
 
         return logEntries;
     }
-    
+
     public void addHandler(Filter filter, Handler handler) {
-        handlerManager.addHandler(filter, handler);
+        handlerManager.addHandler(0, filter, handler);
     }
 
     private void registerBuiltInHandlers() {
 
         Axis2RepositoryHandler axis2RepositoryHandler = new Axis2RepositoryHandler();
-        MediaTypeMatcher axis2MediaTypeMatcher = new MediaTypeMatcher("application/vnd.apache.axis2");
-        handlerManager.addHandler(axis2MediaTypeMatcher, axis2RepositoryHandler);
+        MediaTypeMatcher axis2MediaTypeMatcher =
+                new MediaTypeMatcher("application/vnd.apache.axis2");
+        handlerManager.addHandler(0, axis2MediaTypeMatcher, axis2RepositoryHandler);
 
         SQLQueryHandler sqlQueryHandler = new SQLQueryHandler();
         MediaTypeMatcher sqlMediaTypeMatcher =
                 new MediaTypeMatcher(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
-        handlerManager.addHandler(sqlMediaTypeMatcher, sqlQueryHandler);
+        handlerManager.addHandler(0, sqlMediaTypeMatcher, sqlQueryHandler);
 
         CommentURLHandler commentURLHandler = new CommentURLHandler();
         URLMatcher commentURLMatcher = new URLMatcher();
         commentURLMatcher.setGetPattern(".+;comments:[0-9]+");
         commentURLMatcher.setDeletePattern(".+;comments:[0-9]+");
-        handlerManager.addHandler(commentURLMatcher, commentURLHandler);
+        handlerManager.addHandler(0, commentURLMatcher, commentURLHandler);
 
         CommentCollectionURLHandler commentCollectionURLHandler = new CommentCollectionURLHandler();
         URLMatcher commentCollectionURLMatcher = new URLMatcher();
         commentCollectionURLMatcher.setGetPattern(".+;comments");
-        handlerManager.addHandler(commentCollectionURLMatcher, commentCollectionURLHandler);
+        handlerManager.addHandler(0, commentCollectionURLMatcher, commentCollectionURLHandler);
 
         RatingURLHandler ratingURLHandler = new RatingURLHandler();
         URLMatcher ratingURLMatcher = new URLMatcher();
         ratingURLMatcher.setGetPattern(".+;ratings:.+");
-        handlerManager.addHandler(ratingURLMatcher, ratingURLHandler);
+        handlerManager.addHandler(0, ratingURLMatcher, ratingURLHandler);
 
         RatingCollectionURLHandler ratingCollectionURLHandler = new RatingCollectionURLHandler();
         URLMatcher ratingCollectionURLMatcher = new URLMatcher();
         ratingCollectionURLMatcher.setGetPattern(".+;ratings");
-        handlerManager.addHandler(ratingCollectionURLMatcher, ratingCollectionURLHandler);
+        handlerManager.addHandler(0, ratingCollectionURLMatcher, ratingCollectionURLHandler);
 
         TagURLHandler tagURLHandler = new TagURLHandler();
         URLMatcher tagURLMatcher = new URLMatcher();
         tagURLMatcher.setGetPattern(".+;.+:.+:.+");
-        handlerManager.addHandler(tagURLMatcher, tagURLHandler);
+        handlerManager.addHandler(0, tagURLMatcher, tagURLHandler);
     }
 
 
@@ -1363,43 +1364,33 @@
         RegistryContext registryContext = (RegistryContext)System.
                 getProperties().get(RegistryConstants.REGISTRY_CONTEXT);
         Lifecycle lifeCycle = registryContext.getLifecycle(lifecycle);
-        lifeCycle.associate(resource , this);
+        lifeCycle.associate(resource, this);
         String currentLifecycle = resource.getProperty(Lifecycle.CURRENT_LIFE_CYCLE);
         if (currentLifecycle == null) {
-            resource.setProperty(Lifecycle.CURRENT_LIFE_CYCLE , lifecycle);
+            resource.setProperty(Lifecycle.CURRENT_LIFE_CYCLE, lifecycle);
         }
-        resource.setProperty(Lifecycle.AVAILABLE_LIFE_CYCLES , lifecycle);
-        put(resource.getPath() , resource) ;
+        resource.setProperty(Lifecycle.AVAILABLE_LIFE_CYCLES, lifecycle);
+        put(resource.getPath(), resource);
     }
 
-    public void lifeCycleTransition(String resourcePath) throws RegistryException {
+    public void lifeCycleTransition(String resourcePath, String lifecycleName, String action)
+            throws RegistryException {
         Resource resource = get(resourcePath);
-        String currentLifecycle = resource.getProperty(Lifecycle.CURRENT_LIFE_CYCLE);
-        List lifeCycleNames = resource.getPropertyValues(Lifecycle.AVAILABLE_LIFE_CYCLES);
-        if (lifeCycleNames == null) {
-            throw new RegistryException("No lifecycle are associated with the resource");
-        }
-        if (Lifecycle.COMPLETED.equals(currentLifecycle)) {
-            throw new RegistryException("Invalid operation , resource has completed all its stages");
-        }
 
-        RegistryContext registryContext = (RegistryContext)System.
-                getProperties().get(RegistryConstants.REGISTRY_CONTEXT);
-        Lifecycle[] lifecycles = RegistryUtils.getLifecycles(lifeCycleNames, registryContext);
-        Lifecycle lifecycle ;
-        if (currentLifecycle == null) {
-            lifecycle = lifecycles[0];
-            currentLifecycle = lifecycle.getName();
-        } else {
-            lifecycle = registryContext.getLifecycle(currentLifecycle);
-        }
-        lifecycle.transition(resource , this);
-        resource.setProperty(Lifecycle.CURRENT_LIFE_CYCLE , currentLifecycle);
-        // to keep track of whether we found the next phase or not
-        String nextLifecycle = RegistryUtils.getNextPhaseName(lifecycles, currentLifecycle);
-        resource.setProperty(Lifecycle.CURRENT_LIFE_CYCLE , nextLifecycle);
-    }
+        RequestContext context = new RequestContext(this);
+        context.setResource(resource);
 
+        Lifecycle lifecycle = resource.getLifecycle(lifecycleName);
+        if (lifecycle == null) {
+            throw new RegistryException("Resource at '" + resourcePath +
+                                        "' not associated with lifecycle '" + lifecycleName + "'");
+        }
 
+//        List lifeCycleNames = resource.getPropertyValues(Lifecycle.AVAILABLE_LIFE_CYCLES);
+//        if (lifeCycleNames == null) {
+//            throw new RegistryException("No lifecycle are associated with the resource");
+//        }
 
+        lifecycle.transition(context, action);
+    }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/Repository.java	Thu Mar 13 08:24:15 2008
@@ -114,7 +114,7 @@
 
         // we are just getting the content from the database. not a content modification.
         if (resourceImpl != null && resourceImpl instanceof ResourceImpl) {
-            ((ResourceImpl) resourceImpl).setContentModified(false);
+            resourceImpl.setContentModified(false);
         }
 
         return resourceImpl;

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/HandlerManager.java	Thu Mar 13 08:24:15 2008
@@ -24,13 +24,17 @@
 import org.wso2.registry.users.UserRealm;
 
 import javax.sql.DataSource;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
+import java.util.*;
 
 public class HandlerManager {
 
     private Map<Filter, Handler> handlerMap = new HashMap();
+    private List getFilters = new ArrayList();
+    private List putFilters = new ArrayList();
+    private List deleteFilters = new ArrayList();
+    private List importFilters = new ArrayList();
+    private List putChildFilters = new ArrayList();
+    private List importChildFilters = new ArrayList();
 
     private DataSource dataSource;
     private UserRealm userRealm;
@@ -47,8 +51,25 @@
         this.repository = repository;
     }
 
-    public void addHandler(Filter filter, Handler handler) {
-
+    public void addHandler(int methods, Filter filter, Handler handler) {
+        if ((methods & Filter.GET) != 0) {
+            getFilters.add(filter);
+        }
+        if ((methods & Filter.PUT) != 0) {
+            putFilters.add(filter);
+        }
+        if ((methods & Filter.DELETE) != 0) {
+            deleteFilters.add(filter);
+        }
+        if ((methods & Filter.IMPORT) != 0) {
+            importFilters.add(filter);
+        }
+        if ((methods & Filter.PUT_CHILD) != 0) {
+            putChildFilters.add(filter);
+        }
+        if ((methods & Filter.IMPORT_CHILD) != 0) {
+            importChildFilters.add(filter);
+        }
         filter.setRepository(repository);
 
         handler.setDataSource(dataSource);

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/RequestContext.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/RequestContext.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/RequestContext.java	Thu Mar 13 08:24:15 2008
@@ -18,6 +18,7 @@
 
 import org.wso2.registry.Resource;
 import org.wso2.registry.Collection;
+import org.wso2.registry.Registry;
 
 /**
  * Objects of this class contains the information about the current request to the registry.
@@ -64,6 +65,16 @@
      */
     private Collection parentCollection;
 
+    private Registry registry;
+
+    public RequestContext(Registry registry) {
+        this.registry = registry;
+    }
+
+    public Registry getRegistry() {
+        return registry;
+    }
+
     public boolean isProcessingComplete() {
         return processingComplete;
     }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/Filter.java	Thu Mar 13 08:24:15 2008
@@ -26,6 +26,13 @@
  * associating handler.
  */
 public abstract class Filter {
+    // Bit flags for supported methods
+    public static final int GET = 1;
+    public static final int PUT = 2;
+    public static final int DELETE = 4;
+    public static final int IMPORT = 8;
+    public static final int PUT_CHILD = 16;
+    public static final int IMPORT_CHILD = 32;
 
     /**
      * Repository instance to be used by filter authors. Filter impls may need to access the

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/MediaTypeMatcher.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/MediaTypeMatcher.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/handlers/filters/MediaTypeMatcher.java	Thu Mar 13 08:24:15 2008
@@ -65,11 +65,8 @@
         }
 
         String mType = resource.getMediaType();
-        if (resource != null && mType != null && mType.equals(mediaType)) {
-            return true;
-        }
+        return mType != null && mType.equals(mediaType);
 
-        return false;
     }
 
     public boolean handleImportResource(RequestContext requestContext) throws RegistryException {
@@ -80,11 +77,8 @@
         }
 
         String mType = metadataResource.getMediaType();
-        if (metadataResource != null && mType != null && mType.equals(mediaType)) {
-            return true;
-        }
+        return mType != null && mType.equals(mediaType);
 
-        return false;
     }
 
     public boolean handleDelete(RequestContext requestContext) throws RegistryException {

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/DefaultLifecycle.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/DefaultLifecycle.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/DefaultLifecycle.java	Thu Mar 13 08:24:15 2008
@@ -21,55 +21,92 @@
 import org.wso2.registry.*;
 import org.wso2.registry.config.RegistryContext;
 import org.wso2.registry.jdbc.dao.VersionedResourceDAO;
+import org.wso2.registry.jdbc.handlers.RequestContext;
 import org.wso2.registry.users.UserRealm;
-import org.wso2.registry.utils.RegistryUtils;
-
-import java.util.List;
 
 public class DefaultLifecycle extends Lifecycle {
 
-    public static final String PHASE_CREATED = "Created";
-    public static final String PHASE_DEVELOPED = "Developed";
-    public static final String PHASE_TESTED = "Tested";
-    public static final String PHASE_DEPLOYED = "Deployed";
+    public static final String PHASE_CREATED = "created";
+    public static final String PHASE_DEVELOPED = "developed";
+    public static final String PHASE_TESTED = "tested";
+    public static final String PHASE_DEPLOYED = "deployed";
+
+    public static final String[] phases = new String[]{
+            PHASE_CREATED, PHASE_DEVELOPED, PHASE_TESTED, PHASE_DEPLOYED
+    };
 
-    public void associate(Resource resource, Registry registry) throws RegistryException {
-        // hmm , at the moment I can not find any stuff we should do here ,
-        //  but in the future we have to do some logic processing here
+    // Property to store phase name
+    public static final String PHASE_PROPERTY = "DefaultLifecycle.phase";
 
+    // The only action this lifecycle supports is "promote", which moves to the next phase
+    public static final String ACTION = "promote";
+
+    public void associate(Resource resource, Registry registry) throws RegistryException {
+        // We start off in the CREATED phase
+        resource.setProperty(PHASE_PROPERTY, PHASE_CREATED);
     }
 
     /**
-     * we will do something similar to SVN branching here copy the resource from
-     * one location to other
+     * Do something (change state) - action names are lifecycle-specific, and it's up to the
+     * implementation to decide if a given transition is allowed, and what to do if so.
      *
-     * @param resource : Resource we need to do the transition
-     * @param registry : Registry instance
-     * @throws RegistryException : If something went wrong
+     * @param context the RequestContext containing all the state about this request
+     * @param action  action to perform
+     * @throws org.wso2.registry.RegistryException
+     *          If the condition is not met or some thing is wrong
      */
-    public void transition(Resource resource, Registry registry) throws RegistryException {
-        List lifecyclesNames = resource.getPropertyValues(Lifecycle.AVAILABLE_LIFE_CYCLES);
-        String currentLifecycle = resource.getProperty(Lifecycle.CURRENT_LIFE_CYCLE);
-        RegistryContext registryContext = (RegistryContext) System.
-                getProperties().get(RegistryConstants.REGISTRY_CONTEXT);
-        String nextPhasename = RegistryUtils.getNextPhaseName(RegistryUtils.getLifecycles(
-                lifecyclesNames, registryContext), currentLifecycle);
-        if (!Lifecycle.COMPLETED.equals(nextPhasename)) {
-            String newResourcePath = "/" + nextPhasename.toLowerCase() + resource.getPath();
-            VersionedResourceDAO versionedResourceDAO =
-                    new VersionedResourceDAO(registryContext.getDataSource());
-            UserRealm realm = (UserRealm) System.getProperties().get(
-                    RegistryConstants.REGISTRY_REALM);
-            try {
-                versionedResourceDAO.renameWithoutDelete(resource.getPath(),
-                        newResourcePath,
-                        User.getCurrentUser(),
-                        realm,
-                        registry);
-            } catch (Exception e) {
-                throw new RegistryException("Error while coping the resource");
+    public void transition(RequestContext context, String action) throws RegistryException {
+        if (!ACTION.equals(action)) {
+            throw new RegistryException("Unsupported lifecycle action '" + action +
+                                        "'.  Only valid action is '" + ACTION + "'");
+        }
+        Resource resource = context.getResource();
+        String currentPhase = resource.getProperty(PHASE_PROPERTY);
+        if (currentPhase == null)
+            throw new RegistryException("DefaultLifecycle: Resource '" + resource.getPath() +
+                                        "' has no phase property");
+
+        int i = 0;
+        while (i < phases.length) {
+            if (phases[i].equals(currentPhase)) {
+                break;
             }
+            i++;
+        }
+        if (i == phases.length) {
+            // No such phase!
+            throw new RegistryException("Resource " + resource.getPath() +
+                                        " is in an invalid lifecycle phase ('" + currentPhase +
+                                        "')");
+        }
+        if (i == phases.length - 1) {
+            // We're at the end, no more promoting to do
+            throw new RegistryException(
+                    "Promotion disallowed - resource is at the end of the DefaultLifecycle");
+        }
+
+        String nextPhase = phases[i + 1];
+        String newResourcePath = "/" + nextPhase + "/" + resource.getPath();
+
+        // There has got to be a better way of doing this.  Do we really need to be messing
+        // around with VersionedResourceDAO and realms in here?
 
+        RegistryContext registryContext = (RegistryContext)System.
+                getProperties().get(RegistryConstants.REGISTRY_CONTEXT);
+
+        VersionedResourceDAO versionedResourceDAO =
+                new VersionedResourceDAO(registryContext.getDataSource());
+        UserRealm realm = (UserRealm)System.getProperties().get(
+                RegistryConstants.REGISTRY_REALM);
+        try {
+            versionedResourceDAO.renameWithoutDelete(resource.getPath(),
+                                                     newResourcePath,
+                                                     User.getCurrentUser(),
+                                                     realm,
+                                                     context.getRegistry());
+        } catch (Exception e) {
+            throw new RegistryException("Error while coping the resource");
         }
+
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/Lifecycle.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/Lifecycle.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/Lifecycle.java	Thu Mar 13 08:24:15 2008
@@ -3,6 +3,7 @@
 import org.wso2.registry.Resource;
 import org.wso2.registry.Registry;
 import org.wso2.registry.RegistryException;
+import org.wso2.registry.jdbc.handlers.RequestContext;
 
 public abstract class Lifecycle {
 
@@ -23,38 +24,24 @@
     }
 
     /**
-     * To get the location index of the phase.
+     * Associate a new Resource with this lifecycle.  This could set custom properties, create
+     * sub-directories, etc...  If this throws an Exception, the association has FAILED.
      *
-     * @return : index specified by registry.xml
+     * @param resource Resource which we want to change the state
+     * @param registry Current registry instance
+     * @throws org.wso2.registry.RegistryException
+     *          If the condition is not met or some thing is wrong
      */
-    public int getLocation() {
-        return location;
-    }
-
-
-    public void setLocation(int location) {
-        this.location = location;
-    }
-
-    /**
-     * Associate a new Resource with this lifecycle.  This could
-     * set custom properties, create sub-directories, etc...  If
-     * this throws an Exception, the association has FAILED.
-     *
-     * @param resource : Resource which we want to change the state
-     * @throws org.wso2.registry.RegistryException :If the condition is not met or some thing is wrong
-     * @param registry : Current registry instance
-     */
-    public abstract void associate(Resource resource , Registry registry) throws RegistryException;
+    public abstract void associate(Resource resource, Registry registry) throws RegistryException;
 
     /**
-     * Do something (change state) - action names are lifecycle-
-     * specific, and it's up to the implementation to decide
-     * if a given transition is allowed, and what to do if so.
+     * Do something (change state) - action names are lifecycle-specific, and it's up to the
+     * implementation to decide if a given transition is allowed, and what to do if so.
      *
-     * @param resource : Current Resource
-     * @param registry : Current registry instance
-     * @throws org.wso2.registry.RegistryException : If the condition is not met or some thing is wrong
+     * @param context the RequestContext containing all the state about this request
+     * @param action  action to perform
+     * @throws org.wso2.registry.RegistryException
+     *          If the condition is not met or some thing is wrong
      */
-    public abstract void transition(Resource resource , Registry registry) throws RegistryException;
+    public abstract void transition(RequestContext context, String action) throws RegistryException;
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java	Thu Mar 13 08:24:15 2008
@@ -430,20 +430,22 @@
      * Checks if the current user has PUT permission for the dependentPath. User should have write
      * permission to specify a resourceis dependent on another resource.
      *
-     * @param dependentPath Path of the dependent resource
-     * @param dependencyPaths
+     * @param dependentPath   Path of the dependent resource
+     * @param dependencyPaths a String[] of the dependencies to add
      * @throws RegistryException On authorizing error or an error caused by the underlying core
-     * registry impl.
+     *                           registry impl.
      */
-    public void addDependencies(String dependentPath, String[] dependencyPaths) throws RegistryException {
+    public void addDependencies(String dependentPath, String[] dependencyPaths)
+            throws RegistryException {
 
         String authPath = getAuthorizationPath(dependentPath);
 
         try {
             if (!authorizer.isUserAuthorized(userID, authPath, ActionConstants.PUT)) {
-                String msg = "User: " + userID + " does not have write permission on the resource: " +
-                             authPath + ". Users should have write permission to specify that " +
-                             "resource is dependent on another resource.";
+                String msg =
+                        "User: " + userID + " does not have write permission on the resource: " +
+                        authPath + ". Users should have write permission to specify that " +
+                        "resource is dependent on another resource.";
                 log.info(msg);
                 throw new AuthorizationFailedException(msg);
             }
@@ -757,7 +759,7 @@
         throw new UnsupportedOperationException();
     }
 
-    public void lifeCycleTransition(String resourcePath) throws RegistryException {
+    public void lifeCycleTransition(String resourcePath, String lifecycleName, String action) throws RegistryException {
         throw new UnsupportedOperationException();
     }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/users/def/DefaultAccessControlAdmin.java	Thu Mar 13 08:24:15 2008
@@ -32,6 +32,7 @@
 /**
  * @see org.wso2.usermanager.AccessControlAdmin
  */
+ at SuppressWarnings({"ThrowFromFinallyBlock"})
 public class DefaultAccessControlAdmin
         extends DefaultAuthorizer implements AccessControlAdmin {
 
@@ -60,7 +61,7 @@
             getPermission.setString(2, action);
 
             ResultSet rs = getPermission.executeQuery();
-            int pid = -1;
+            int pid;
             if (rs.next()) {
                 pid = rs.getInt(DefaultRealmConstants.COLUMN_NAME_ID);
             } else {
@@ -124,7 +125,7 @@
             getPermission.setString(2, action);
 
             ResultSet rs = getPermission.executeQuery();
-            String pid = null;
+            String pid;
             if (rs.next()) {
                 pid = rs.getString(DefaultRealmConstants.COLUMN_NAME_ID);
             } else {

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/AuthorizationUtil.java	Thu Mar 13 08:24:15 2008
@@ -329,8 +329,8 @@
     }
 
     private static boolean containsString(String value, String[] array) {
-        for (int i = 0; i < array.length; i++) {
-            if (value.equals(array[i])) {
+        for (String anArray : array) {
+            if (value.equals(anArray)) {
                 return true;
             }
         }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/utils/RegistryUtils.java	Thu Mar 13 08:24:15 2008
@@ -19,7 +19,6 @@
 import org.wso2.registry.RegistryConstants;
 import org.wso2.registry.config.RegistryContext;
 import org.wso2.registry.lifecycle.Lifecycle;
-import org.wso2.registry.lifecycle.LifecycleComparator;
 
 import java.util.List;
 import java.util.Arrays;
@@ -87,34 +86,4 @@
 
         return parentPath;
     }
-
-     public static Lifecycle[] getLifecycles(List lifeCycleNames, RegistryContext registryContext) {
-        Lifecycle lifecycles [] = new Lifecycle[lifeCycleNames.size()];
-        for (int i = 0; i < lifeCycleNames.size(); i++) {
-            String s = (String) lifeCycleNames.get(i);
-            lifecycles[i] = registryContext.getLifecycle(s);
-        }
-        // sorting the lifecycle according to the location order
-        Arrays.sort(lifecycles ,new LifecycleComparator());
-        return lifecycles;
-    }
-     public static String getNextPhaseName(Lifecycle[] lifecycles, String currentLifecycle) {
-        boolean found = false ;
-        String nextLifecycle = null;
-        for (int i = 0; i < lifecycles.length; i++) {
-            Lifecycle lc = lifecycles[i];
-            if (found) {
-                nextLifecycle = lc.getName();
-                break;
-            }
-            if (currentLifecycle.equals(lc.getName())) {
-                found = true;
-            }
-
-        }
-        if (currentLifecycle.equals(nextLifecycle) || nextLifecycle == null ){
-            nextLifecycle = Lifecycle.COMPLETED;
-        }
-        return nextLifecycle;
-    }
 }



More information about the Registry-dev mailing list