Coverage report

  %line %branch
org.apache.fulcrum.security.memory.MemoryGroupManagerImpl
68% 
86% 

 1  
 package org.apache.fulcrum.security.memory;
 2  
 /*
 3  
  *  Copyright 2001-2004 The Apache Software Foundation
 4  
  *
 5  
  *  Licensed under the Apache License, Version 2.0 (the "License");
 6  
  *  you may not use this file except in compliance with the License.
 7  
  *  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  *  Unless required by applicable law or agreed to in writing, software
 12  
  *  distributed under the License is distributed on an "AS IS" BASIS,
 13  
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  *  See the License for the specific language governing permissions and
 15  
  *  limitations under the License.
 16  
  */
 17  
 import java.util.ArrayList;
 18  
 import java.util.List;
 19  
 
 20  
 import org.apache.commons.logging.Log;
 21  
 import org.apache.commons.logging.LogFactory;
 22  
 import org.apache.fulcrum.security.GroupManager;
 23  
 import org.apache.fulcrum.security.entity.Group;
 24  
 import org.apache.fulcrum.security.spi.AbstractGroupManager;
 25  
 import org.apache.fulcrum.security.util.DataBackendException;
 26  
 import org.apache.fulcrum.security.util.EntityExistsException;
 27  
 import org.apache.fulcrum.security.util.GroupSet;
 28  
 import org.apache.fulcrum.security.util.UnknownEntityException;
 29  
 
 30  
 /**
 31  
  * This implementation keeps all objects in memory.  This is mostly meant to help
 32  
  * with testing and prototyping of ideas.
 33  
  *
 34  
  * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
 35  
  * @version $Id: MemoryGroupManagerImpl.java 223060 2004-07-07 16:51:27Z epugh $
 36  
  */
 37  387
 public class MemoryGroupManagerImpl
 38  
     extends AbstractGroupManager
 39  
     implements GroupManager
 40  
 {
 41  
     /** Logging */
 42  33
     private static Log log = LogFactory.getLog(MemoryGroupManagerImpl.class);
 43  33
     private static List groups = new ArrayList();
 44  
 
 45  
     /** Our Unique ID counter */
 46  33
     private static int uniqueId = 0;
 47  
 
 48  
     /**
 49  
     	 * Retrieves all groups defined in the system.
 50  
     	 *
 51  
     	 * @return the names of all groups defined in the system.
 52  
     	 * @throws DataBackendException if there was an error accessing the
 53  
     	 *         data backend.
 54  
     	 */
 55  
     public GroupSet getAllGroups() throws DataBackendException
 56  
     {
 57  105
         return new GroupSet(groups);
 58  
     }
 59  
     /**
 60  
     	* Removes a Group from the system.
 61  
     	*
 62  
     	* @param group The object describing the group to be removed.
 63  
     	* @throws DataBackendException if there was an error accessing the data
 64  
     	*         backend.
 65  
     	* @throws UnknownEntityException if the group does not exist.
 66  
     	*/
 67  
     public synchronized void removeGroup(Group group)
 68  
         throws DataBackendException, UnknownEntityException
 69  
     {
 70  6
         boolean groupExists = false;
 71  
         try
 72  
         {
 73  6
             groupExists = checkExists(group);
 74  6
             if (groupExists)
 75  
             {
 76  6
                 groups.remove(group);
 77  6
                 return;
 78  
             }
 79  
             else
 80  
             {
 81  0
                 throw new UnknownEntityException(
 82  0
                     "Unknown group '" + group + "'");
 83  
             }
 84  
         }
 85  0
         catch (Exception e)
 86  
         {
 87  0
             log.error("Failed to delete a Group");
 88  0
             log.error(e);
 89  0
             throw new DataBackendException("removeGroup(Group) failed", e);
 90  
         }
 91  
         finally
 92  
         {
 93  
         }
 94  
     }
 95  
     /**
 96  
     	* Renames an existing Group.
 97  
     	*
 98  
     	* @param group The object describing the group to be renamed.
 99  
     	* @param name the new name for the group.
 100  
     	* @throws DataBackendException if there was an error accessing the data
 101  
     	*         backend.
 102  
     	* @throws UnknownEntityException if the group does not exist.
 103  
     	*/
 104  
     public synchronized void renameGroup(Group group, String name)
 105  
         throws DataBackendException, UnknownEntityException
 106  
     {
 107  6
         boolean groupExists = false;
 108  
         try
 109  
         {
 110  6
             groupExists = checkExists(group);
 111  6
             if (groupExists)
 112  
             {
 113  6
                 groups.remove(group);
 114  6
                 group.setName(name);
 115  6
                 groups.add(group);
 116  
             }
 117  
             else
 118  
             {
 119  0
                 throw new UnknownEntityException(
 120  0
                     "Unknown group '" + group + "'");
 121  
             }
 122  
         }
 123  0
         catch (Exception e)
 124  
         {
 125  0
             throw new DataBackendException("renameGroup(Group,String)", e);
 126  
         }
 127  
         finally
 128  
         {
 129  
         }
 130  6
     }
 131  
     
 132  
     /**
 133  
      * Determines if the <code>Group</code> exists in the security system.
 134  
      *
 135  
      * @param group a <code>Group</code> value
 136  
      * @return true if the group exists in the system, false otherwise
 137  
      * @throws DataBackendException when more than one Group with
 138  
      *         the same name exists.
 139  
      * @throws Exception A generic exception.
 140  
      */
 141  
     public boolean checkExists(String groupName) throws DataBackendException
 142  
     {     
 143  396
         return MemoryHelper.checkExists(groups,groupName);      
 144  
     }    
 145  
     /**
 146  
     	* Creates a new group with specified attributes.
 147  
     	*
 148  
     	* @param group the object describing the group to be created.
 149  
     	* @return a new Group object that has id set up properly.
 150  
     	* @throws DataBackendException if there was an error accessing the data
 151  
     	*         backend.
 152  
     	* @throws EntityExistsException if the group already exists.
 153  
     	*/
 154  
     public synchronized Group persistNewGroup(Group group)
 155  
         throws DataBackendException
 156  
     {
 157  
         
 158  171
             group.setId(MemoryHelper.getUniqueId());
 159  171
             groups.add(group);
 160  
             // return the object with correct id
 161  171
             return group;
 162  
        
 163  
     }
 164  
     
 165  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.