[Registry-dev] svn commit r14767 - in trunk/registry/modules/core/src/main/java/org/wso2/registry: . app config jdbc jdbc/dao lifecycle secure servlet utils

svn at wso2.org svn at wso2.org
Thu Mar 13 02:08:20 PDT 2008


Author: deepal
Date: Thu Mar 13 02:08:01 2008
New Revision: 14767

Log:

first checking for lifecycle handling 
 TODOS
 - security handling 
 - few useful lifecycle implementations

Added:
   trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/
   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/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/config/RegistryContext.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/dao/VersionedResourceDAO.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
   trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml
   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 02:08:01 2008
@@ -257,4 +257,21 @@
                        Date from,
                        Date to,
                        boolean recentFirst) throws RegistryException;
+
+    /**
+     * Associate a lifecycle into a resource.
+     * @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 ;
+
+    /**
+     * 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
+     */
+    void lifeCycleTransition(String resourcePath)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 02:08:01 2008
@@ -15,6 +15,8 @@
  */
 package org.wso2.registry;
 
+import org.wso2.registry.lifecycle.Lifecycle;
+
 import java.util.Date;
 import java.util.Properties;
 import java.util.List;
@@ -74,4 +76,8 @@
     InputStream getContentStream() throws RegistryException;
 
     void setContentStream(InputStream contentStream);
+
+    Lifecycle[] getLifecycles();
+
+    Lifecycle getCurrentLifecycle();
 }

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 02:08:01 2008
@@ -22,6 +22,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.registry.jdbc.dao.VersionedResourceDAO;
+import org.wso2.registry.lifecycle.Lifecycle;
 
 import javax.sql.DataSource;
 import java.sql.Timestamp;
@@ -158,6 +159,7 @@
      */
     private InputStream contentStream;
 
+
     /**
      * Registry datasource. This is to be used only by the resource implemetation and users of the
      * resource are not needed to use this. Some attributes of the resource (e.g. content) is
@@ -473,4 +475,15 @@
     public void setContentModified(boolean contentModified) {
         this.contentModified = contentModified;
     }
+
+
+    public Lifecycle[] getLifecycles() {
+        // all the lifecycle assigned to the resource
+        return new Lifecycle[0];
+    }
+
+    public Lifecycle getCurrentLifecycle() {
+        // Current Lifecycle
+        return null;
+    }
 }

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 02:08:01 2008
@@ -842,4 +842,12 @@
 //        }
     }
 
+
+    public void associateLifeCycle(String resourcePath, String lifecycle) throws RegistryException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void lifeCycleTransition(String resourcePath) 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 02:08:01 2008
@@ -25,6 +25,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.registry.RegistryException;
+import org.wso2.registry.lifecycle.Lifecycle;
 import org.wso2.registry.jdbc.handlers.Handler;
 import org.wso2.registry.jdbc.handlers.filters.Filter;
 import org.wso2.registry.i18n.Messages;
@@ -183,6 +184,29 @@
 
                     registryContext.addQueryProcessor(queryProcessorConfiguration);
                 }
+                Iterator lifecycleElement = configElement.
+                        getChildrenWithName(new QName("lifecycle "));
+                if (lifecycleElement != null) {
+                    while (lifecycleElement.hasNext()) {
+                        OMElement lifecycle = (OMElement) lifecycleElement.next();
+                        String name = lifecycle.getAttributeValue(new QName("name"));
+                        String order = lifecycle.getAttributeValue(new QName("order"));
+                        String clazz = lifecycle.getAttributeValue(new QName("class"));
+                        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) {
+                            throw new RegistryException("Unable to load the class : " + clazz) ;
+                        }
+                        if (name == null || order == null || clazz == null) {
+                            throw new RegistryException("Invalid lifecycle elemet , required " +
+                                    "values are missing " + lifecycle.toString());
+                        }
+                    }
+                }
             }
 
         } catch (XMLStreamException e) {

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java	Thu Mar 13 02:08:01 2008
@@ -19,11 +19,13 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.wso2.registry.RegistryException;
+import org.wso2.registry.lifecycle.Lifecycle;
 import org.wso2.registry.i18n.Messages;
 import org.wso2.registry.jdbc.hsql.DBUtils;
 import org.wso2.registry.jdbc.utils.RegistryDataSource;
 import org.wso2.registry.secure.HSQLDBInitializer;
 
+import javax.sql.DataSource;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.*;
@@ -42,6 +44,8 @@
     private List mediaTypeHandlers = new ArrayList();
     private List urlHandlers = new ArrayList();
     private List queryProcessors = new ArrayList();
+    private Map lifecycles = new HashMap();
+    private DataSource dataSource ;
 
     public RegistryContext() {
     }
@@ -139,6 +143,15 @@
         urlHandlers.add(urlHandler);
     }
 
+    public void addLifecycle(Lifecycle lifecycle) {
+        lifecycles.put(lifecycle.getName() ,lifecycle);
+    }
+
+    public Lifecycle getLifecycle(String name){
+        return (Lifecycle) lifecycles.get(name);
+    }
+
+
     public List getQueryProcessors() {
         return queryProcessors;
     }
@@ -161,4 +174,13 @@
         }
         return basePath;
     }
+
+
+    public DataSource getDataSource() {
+        return dataSource;
+    }
+
+    public void setDataSource(DataSource dataSource) {
+        this.dataSource = dataSource;
+    }
 }

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 02:08:01 2008
@@ -23,6 +23,8 @@
 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.config.RegistryContext;
 import org.wso2.registry.exceptions.ResourceNotFoundException;
 import org.wso2.registry.i18n.Messages;
 import org.wso2.registry.jdbc.dao.*;
@@ -1354,4 +1356,50 @@
         handlerManager.addHandler(tagURLMatcher, tagURLHandler);
     }
 
+
+    public void associateLifeCycle(String resourcePath, String lifecycle) throws RegistryException {
+        //TODO need to do the security validation here
+        Resource resource = get(resourcePath);
+        RegistryContext registryContext = (RegistryContext)System.
+                getProperties().get(RegistryConstants.REGISTRY_CONTEXT);
+        Lifecycle lifeCycle = registryContext.getLifecycle(lifecycle);
+        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.AVAILABLE_LIFE_CYCLES , lifecycle);
+        put(resource.getPath() , resource) ;
+    }
+
+    public void lifeCycleTransition(String resourcePath) 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);
+    }
+
+
+
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/dao/VersionedResourceDAO.java	Thu Mar 13 02:08:01 2008
@@ -974,6 +974,62 @@
     }
 
     /**
+     * This method will copy a resource from oldpath to newpath , the internal implementation is
+     * such that copy all the resources from oldpath to new path including tags , comments and ratings.
+     *
+     * @param oldPath : Current path of the resource
+     * @param newPath : Where to move the resource
+     * @param conn    : Connection to DB
+     * @param userId  : current user
+     * @param realm   : Realm
+     * @throws org.wso2.registry.RegistryException
+     *          : If something went wrong
+     */
+    public void renameWithoutDelete(String oldPath,
+                               String newPath,
+                               String userId,
+                               UserRealm realm,
+                               Registry registry) throws SQLException, RegistryException, IOException {
+        Connection conn = dataSource.getConnection();
+        ResourceImpl resource = getLatestVersion(oldPath, conn);
+        String resourcePath = resource.getPath();
+        long resourceID = resource.getId();
+        //to see whether the patent node is there in the table , if not need to add that
+        createParentCollections(newPath, conn, userId, realm);
+        // if the resource is a directory then need to populate the dependecy table with
+        // the new resource id , while keeping the old one as it is
+        if (resource.isDirectory()) {
+            copyResource(oldPath, newPath, registry, true, conn);
+        } else {
+            // Then its just need to add the resource and no need to update any of the
+            // dependecy tables
+            resource.setPath(newPath);
+            if (resource.getAuthorUserName() == null) {
+                resource.setAuthorUserName(userId);
+            }
+            resource.setLastUpdaterUserName(userId);
+            add(resource, conn);
+            AuthorizationUtil.setDefaultAuthorizations(realm, newPath, userId);
+            long newResourceID = getResourceID(newPath, conn);
+            resource.setId(newResourceID);
+            addResourceVersion(resource, conn);
+            resource.setPath(resourcePath);
+
+            long fromResourceId = getResourceID(oldPath, conn);
+            //copying the comments
+            CommentsDAO commentsDAO = new CommentsDAO();
+            commentsDAO.copyComments(oldPath, resourceID, conn);
+            //coping the tags
+            TagsDAO tags = new TagsDAO(dataSource);
+            tags.copyTags(fromResourceId, resourceID, conn);
+
+            // copy ratings
+            RatingsDAO ratingsDAO = new RatingsDAO();
+            ratingsDAO.copyRatings(fromResourceId, resourceID, conn);
+
+        }
+    }
+    /**
      * This method will move a resource from oldpath to newpath , the internal implementation is
      * such that frit the release will be deleted from oldPath parent and will be added to the
      * newptah so if the oldpath is "foo/bar/r1" then the r1 will be removed from foo/bar. However

Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/DefaultLifecycle.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/DefaultLifecycle.java	Thu Mar 13 02:08:01 2008
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.registry.lifecycle;
+
+import org.wso2.registry.*;
+import org.wso2.registry.config.RegistryContext;
+import org.wso2.registry.jdbc.dao.VersionedResourceDAO;
+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 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
+
+    }
+
+    /**
+     * we will do something similar to SVN branching here copy the resource from
+     * one location to other
+     *
+     * @param resource : Resource we need to do the transition
+     * @param registry : Registry instance
+     * @throws RegistryException : If something went 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");
+            }
+
+        }
+    }
+}

Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/Lifecycle.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/Lifecycle.java	Thu Mar 13 02:08:01 2008
@@ -0,0 +1,60 @@
+package org.wso2.registry.lifecycle;
+
+import org.wso2.registry.Resource;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+
+public abstract class Lifecycle {
+
+    public static final String CURRENT_LIFE_CYCLE = "currentPhase";
+    public static final String AVAILABLE_LIFE_CYCLES = "AvailablePhases";
+    public static final String COMPLETED = "completed";
+
+    private String name;
+    private int location;
+
+    public String getName() {
+        return name;
+    }
+
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * To get the location index of the phase.
+     *
+     * @return : index specified by registry.xml
+     */
+    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;
+
+    /**
+     * 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
+     */
+    public abstract void transition(Resource resource , Registry registry) throws RegistryException;
+}

Added: trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/LifecycleComparator.java
==============================================================================
--- (empty file)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/lifecycle/LifecycleComparator.java	Thu Mar 13 02:08:01 2008
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.registry.lifecycle;
+
+import java.util.Comparator;
+
+public class LifecycleComparator implements Comparator {
+
+    public int compare(Object object1, Object object2) {
+        Lifecycle l1 = (Lifecycle) object1;
+        Lifecycle l2 = (Lifecycle) object2;
+        if (l1.getLocation() > l2.getLocation()) {
+            return 1;
+        } else if (l1.getLocation() < l2.getLocation()) {
+            return -1;
+        } else {
+            return 0;
+        }
+    }
+}

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 02:08:01 2008
@@ -752,4 +752,12 @@
 
         return preparedPath;
     }
+
+     public void associateLifeCycle(String resourcePath, String lifecycle) throws RegistryException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void lifeCycleTransition(String resourcePath) throws RegistryException {
+        throw new UnsupportedOperationException();
+    }
 }

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java	Thu Mar 13 02:08:01 2008
@@ -117,7 +117,7 @@
                             dbConfiguration.getUserName(),
                             dbConfiguration.getPassWord());
                 }
-
+                registryContext.setDataSource(dataSource);
                 registryRealm = new RegistryRealm(dataSource);
                 coreRegistry = new JDBCRegistry(dataSource, registryRealm);
 

Modified: trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml	(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/registry.xml	Thu Mar 13 02:08:01 2008
@@ -55,6 +55,11 @@
         </filter>
     </handler>
 
+    <lifecycle name="Created" order="1" class="org.wso2.registry.lifecycle.DefaultLifecycle"/>
+    <lifecycle name="Developed" order="2" class="org.wso2.registry.lifecycle.DefaultLifecycle"/>
+    <lifecycle name="Tested" order="3" class="org.wso2.registry.lifecycle.DefaultLifecycle"/>
+    <lifecycle name="Deployed" order="4" class="org.wso2.registry.lifecycle.DefaultLifecycle"/>
+
     <!--<mediaTypeHandler>-->
         <!--<mediaType>application/vnd.apache.synapse</mediaType>-->
         <!--<handler>org.wso2.registry.jdbc.mediatypes.builtin.SynapseRepositoryMediaTypeHandler</handler>-->

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 02:08:01 2008
@@ -17,6 +17,12 @@
 package org.wso2.registry.utils;
 
 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;
 
 public class RegistryUtils {
 
@@ -81,4 +87,34 @@
 
         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