You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by tv...@apache.org on 2007/05/05 08:58:51 UTC

svn commit: r535465 [31/49] - in /jakarta/turbine/fulcrum/trunk: ./ bsf/ bsf/src/java/org/apache/fulcrum/bsf/ bsf/src/test/ bsf/xdocs/ cache/ cache/src/java/org/apache/fulcrum/cache/ cache/src/java/org/apache/fulcrum/cache/impl/ cache/src/test/ cache/s...

Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java?view=diff&rev=535465&r1=535464&r2=535465
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicRole.java Fri May  4 23:58:06 2007
@@ -1,306 +1,309 @@
-package org.apache.fulcrum.security.torque.dynamic;
-/*
- *  Copyright 2001-2004 The Apache Software Foundation
- *
- *  Licensed 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.
- */
-import java.sql.Connection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.fulcrum.security.entity.Group;
-import org.apache.fulcrum.security.entity.Permission;
-import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
-import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicGroup;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRole;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRolePeer;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicPermission;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicPermissionPeer;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePeer;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermission;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermissionPeer;
-import org.apache.fulcrum.security.util.GroupSet;
-import org.apache.fulcrum.security.util.PermissionSet;
-import org.apache.torque.TorqueException;
-import org.apache.torque.om.SimpleKey;
-import org.apache.torque.util.Criteria;
-/**
- * This abstract class provides the SecurityInterface to the managers.
- *
- * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
- * @version $Id:$
- */
-public abstract class TorqueAbstractDynamicRole extends TorqueAbstractSecurityEntity
-    implements DynamicRole
-{
-    /** a cache of group objects */
-    private Set groupSet = null;
-
-    /** a cache of permission objects */
-    private Set permissionSet = null;
-    
-    /**
-     * Forward reference to generated code
-     * 
-     * Get a list of association objects, pre-populated with their TorqueDynamicPermission 
-     * objects.
-     * 
-     * @param criteria Criteria to define the selection of records
-     * @throws TorqueException
-     * 
-     * @return a list of Role/Permission relations
-     */
-    protected abstract List getTorqueDynamicRolePermissionsJoinTorqueDynamicPermission(Criteria criteria)
-        throws TorqueException;
-
-    /**
-     * Forward reference to generated code
-     * 
-     * Get a list of association objects, pre-populated with their TorqueDynamicGroup 
-     * objects.
-     * 
-     * @param criteria Criteria to define the selection of records
-     * @throws TorqueException
-     * 
-     * @return a list of Group/Role relations
-     */
-    protected abstract List getTorqueDynamicGroupRolesJoinTorqueDynamicGroup(Criteria criteria)
-        throws TorqueException;
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#addGroup(org.apache.fulcrum.security.entity.Group)
-     */
-    public void addGroup(Group group)
-    {
-        getGroups().add(group);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#addPermission(org.apache.fulcrum.security.entity.Permission)
-     */
-    public void addPermission(Permission permission)
-    {
-        getPermissions().add(permission);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getGroups()
-     */
-    public GroupSet getGroups()
-    {
-        if (groupSet == null)
-        {
-            groupSet = new GroupSet();
-        }
-        else if(!(groupSet instanceof GroupSet))
-        {
-            groupSet = new GroupSet(groupSet);
-        }
-
-        return (GroupSet)groupSet;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getGroupsAsSet()
-     */
-    public Set getGroupsAsSet()
-    {
-        return groupSet;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getPermissions()
-     */
-    public PermissionSet getPermissions()
-    {
-        if (permissionSet == null)
-        {
-            permissionSet = new PermissionSet();
-        }
-        else if(!(permissionSet instanceof PermissionSet))
-        {
-            permissionSet = new PermissionSet(permissionSet);
-        }
-
-        return (PermissionSet)permissionSet;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getPermissionsAsSet()
-     */
-    public Set getPermissionsAsSet()
-    {
-        return permissionSet;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#removeGroup(org.apache.fulcrum.security.entity.Group)
-     */
-    public void removeGroup(Group group)
-    {
-        getGroups().remove(group);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#removePermission(org.apache.fulcrum.security.entity.Permission)
-     */
-    public void removePermission(Permission permission)
-    {
-        getPermissions().remove(permission);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setGroups(org.apache.fulcrum.security.util.GroupSet)
-     */
-    public void setGroups(GroupSet groups)
-    {
-        if (groups != null)
-        {
-            this.groupSet = groups;
-        }
-        else
-        {
-            this.groupSet = new GroupSet();
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setGroupsAsSet(java.util.Set)
-     */
-    public void setGroupsAsSet(Set groups)
-    {
-        setGroups(new GroupSet(groups));
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setPermissions(org.apache.fulcrum.security.util.PermissionSet)
-     */
-    public void setPermissions(PermissionSet permissionSet)
-    {
-        if (permissionSet != null)
-        {
-            this.permissionSet = permissionSet;
-        }
-        else
-        {
-            this.permissionSet = new PermissionSet();
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setPermissionsAsSet(java.util.Set)
-     */
-    public void setPermissionsAsSet(Set permissions)
-    {
-        setPermissions(new PermissionSet(permissions));
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
-     */
-    public String getDatabaseName()
-    {
-        return TorqueDynamicPermissionPeer.DATABASE_NAME;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
-     */
-    public void retrieveAttachedObjects(Connection con) throws TorqueException
-    {
-        this.permissionSet = new PermissionSet();
-        
-        // the generated method that allows a Connection parameter is missing
-        List rolepermissions = getTorqueDynamicRolePermissionsJoinTorqueDynamicPermission(new Criteria());
-
-        for (Iterator i = rolepermissions.iterator(); i.hasNext();)
-        {
-            TorqueDynamicRolePermission tdrp = (TorqueDynamicRolePermission)i.next(); 
-            permissionSet.add(tdrp.getTorqueDynamicPermission());
-        }
-
-        this.groupSet = new GroupSet();
-        
-        // the generated method that allows a Connection parameter is missing
-        List grouproles = getTorqueDynamicGroupRolesJoinTorqueDynamicGroup(new Criteria());
-
-        for (Iterator i = grouproles.iterator(); i.hasNext();)
-        {
-            TorqueDynamicGroupRole tdgr = (TorqueDynamicGroupRole)i.next(); 
-            groupSet.add(tdgr.getTorqueDynamicGroup());
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
-     */
-    public void update(Connection con) throws TorqueException
-    {
-        if (permissionSet != null)
-        {
-            Criteria criteria = new Criteria();
-            
-            /* remove old entries */
-            criteria.add(TorqueDynamicRolePermissionPeer.ROLE_ID, getEntityId());
-            TorqueDynamicRolePermissionPeer.doDelete(criteria, con);
-
-            for (Iterator i = permissionSet.iterator(); i.hasNext();)
-            {
-                TorqueDynamicPermission permission = (TorqueDynamicPermission)i.next();
-
-                TorqueDynamicRolePermission rp = new TorqueDynamicRolePermission();
-                rp.setPermissionId(permission.getEntityId());
-                rp.setRoleId(getEntityId());
-                rp.save(con);
-            }
-        }
-        
-        if (groupSet != null)
-        {
-            Criteria criteria = new Criteria();
-            
-            /* remove old entries */
-            criteria.add(TorqueDynamicGroupRolePeer.ROLE_ID, getEntityId());
-            TorqueDynamicGroupRolePeer.doDelete(criteria, con);
-
-            for (Iterator i = groupSet.iterator(); i.hasNext();)
-            {
-                TorqueDynamicGroup group = (TorqueDynamicGroup)i.next();
-
-                TorqueDynamicGroupRole gr = new TorqueDynamicGroupRole();
-                gr.setGroupId(group.getEntityId());
-                gr.setRoleId(getEntityId());
-                gr.save(con);
-            }
-        }
-        
-        try
-        {
-            save(con);
-        }
-        catch (Exception e)
-        {
-            throw new TorqueException(e);
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
-     */
-    public void delete() throws TorqueException
-    {
-        TorqueDynamicRolePeer.doDelete(SimpleKey.keyFor(getEntityId()));
-    }
-}
\ No newline at end of file
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * 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.
+ */
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.Permission;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroup;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRole;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupRolePeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicPermission;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicPermissionPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermission;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePermissionPeer;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.fulcrum.security.util.PermissionSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractDynamicRole extends TorqueAbstractSecurityEntity
+    implements DynamicRole
+{
+    /** a cache of group objects */
+    private Set groupSet = null;
+
+    /** a cache of permission objects */
+    private Set permissionSet = null;
+
+    /**
+     * Forward reference to generated code
+     *
+     * Get a list of association objects, pre-populated with their TorqueDynamicPermission
+     * objects.
+     *
+     * @param criteria Criteria to define the selection of records
+     * @throws TorqueException
+     *
+     * @return a list of Role/Permission relations
+     */
+    protected abstract List getTorqueDynamicRolePermissionsJoinTorqueDynamicPermission(Criteria criteria)
+        throws TorqueException;
+
+    /**
+     * Forward reference to generated code
+     *
+     * Get a list of association objects, pre-populated with their TorqueDynamicGroup
+     * objects.
+     *
+     * @param criteria Criteria to define the selection of records
+     * @throws TorqueException
+     *
+     * @return a list of Group/Role relations
+     */
+    protected abstract List getTorqueDynamicGroupRolesJoinTorqueDynamicGroup(Criteria criteria)
+        throws TorqueException;
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#addGroup(org.apache.fulcrum.security.entity.Group)
+     */
+    public void addGroup(Group group)
+    {
+        getGroups().add(group);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#addPermission(org.apache.fulcrum.security.entity.Permission)
+     */
+    public void addPermission(Permission permission)
+    {
+        getPermissions().add(permission);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getGroups()
+     */
+    public GroupSet getGroups()
+    {
+        if (groupSet == null)
+        {
+            groupSet = new GroupSet();
+        }
+        else if(!(groupSet instanceof GroupSet))
+        {
+            groupSet = new GroupSet(groupSet);
+        }
+
+        return (GroupSet)groupSet;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getGroupsAsSet()
+     */
+    public Set getGroupsAsSet()
+    {
+        return groupSet;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getPermissions()
+     */
+    public PermissionSet getPermissions()
+    {
+        if (permissionSet == null)
+        {
+            permissionSet = new PermissionSet();
+        }
+        else if(!(permissionSet instanceof PermissionSet))
+        {
+            permissionSet = new PermissionSet(permissionSet);
+        }
+
+        return (PermissionSet)permissionSet;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#getPermissionsAsSet()
+     */
+    public Set getPermissionsAsSet()
+    {
+        return permissionSet;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#removeGroup(org.apache.fulcrum.security.entity.Group)
+     */
+    public void removeGroup(Group group)
+    {
+        getGroups().remove(group);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#removePermission(org.apache.fulcrum.security.entity.Permission)
+     */
+    public void removePermission(Permission permission)
+    {
+        getPermissions().remove(permission);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setGroups(org.apache.fulcrum.security.util.GroupSet)
+     */
+    public void setGroups(GroupSet groups)
+    {
+        if (groups != null)
+        {
+            this.groupSet = groups;
+        }
+        else
+        {
+            this.groupSet = new GroupSet();
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setGroupsAsSet(java.util.Set)
+     */
+    public void setGroupsAsSet(Set groups)
+    {
+        setGroups(new GroupSet(groups));
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setPermissions(org.apache.fulcrum.security.util.PermissionSet)
+     */
+    public void setPermissions(PermissionSet permissionSet)
+    {
+        if (permissionSet != null)
+        {
+            this.permissionSet = permissionSet;
+        }
+        else
+        {
+            this.permissionSet = new PermissionSet();
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicRole#setPermissionsAsSet(java.util.Set)
+     */
+    public void setPermissionsAsSet(Set permissions)
+    {
+        setPermissions(new PermissionSet(permissions));
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return TorqueDynamicPermissionPeer.DATABASE_NAME;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
+     */
+    public void retrieveAttachedObjects(Connection con) throws TorqueException
+    {
+        this.permissionSet = new PermissionSet();
+
+        // the generated method that allows a Connection parameter is missing
+        List rolepermissions = getTorqueDynamicRolePermissionsJoinTorqueDynamicPermission(new Criteria());
+
+        for (Iterator i = rolepermissions.iterator(); i.hasNext();)
+        {
+            TorqueDynamicRolePermission tdrp = (TorqueDynamicRolePermission)i.next();
+            permissionSet.add(tdrp.getTorqueDynamicPermission());
+        }
+
+        this.groupSet = new GroupSet();
+
+        // the generated method that allows a Connection parameter is missing
+        List grouproles = getTorqueDynamicGroupRolesJoinTorqueDynamicGroup(new Criteria());
+
+        for (Iterator i = grouproles.iterator(); i.hasNext();)
+        {
+            TorqueDynamicGroupRole tdgr = (TorqueDynamicGroupRole)i.next();
+            groupSet.add(tdgr.getTorqueDynamicGroup());
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
+     */
+    public void update(Connection con) throws TorqueException
+    {
+        if (permissionSet != null)
+        {
+            Criteria criteria = new Criteria();
+
+            /* remove old entries */
+            criteria.add(TorqueDynamicRolePermissionPeer.ROLE_ID, getEntityId());
+            TorqueDynamicRolePermissionPeer.doDelete(criteria, con);
+
+            for (Iterator i = permissionSet.iterator(); i.hasNext();)
+            {
+                TorqueDynamicPermission permission = (TorqueDynamicPermission)i.next();
+
+                TorqueDynamicRolePermission rp = new TorqueDynamicRolePermission();
+                rp.setPermissionId(permission.getEntityId());
+                rp.setRoleId(getEntityId());
+                rp.save(con);
+            }
+        }
+
+        if (groupSet != null)
+        {
+            Criteria criteria = new Criteria();
+
+            /* remove old entries */
+            criteria.add(TorqueDynamicGroupRolePeer.ROLE_ID, getEntityId());
+            TorqueDynamicGroupRolePeer.doDelete(criteria, con);
+
+            for (Iterator i = groupSet.iterator(); i.hasNext();)
+            {
+                TorqueDynamicGroup group = (TorqueDynamicGroup)i.next();
+
+                TorqueDynamicGroupRole gr = new TorqueDynamicGroupRole();
+                gr.setGroupId(group.getEntityId());
+                gr.setRoleId(getEntityId());
+                gr.save(con);
+            }
+        }
+
+        try
+        {
+            save(con);
+        }
+        catch (Exception e)
+        {
+            throw new TorqueException(e);
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+     */
+    public void delete() throws TorqueException
+    {
+        TorqueDynamicRolePeer.doDelete(SimpleKey.keyFor(getEntityId()));
+    }
+}

Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java?view=diff&rev=535465&r1=535464&r2=535465
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueAbstractDynamicUser.java Fri May  4 23:58:06 2007
@@ -1,340 +1,343 @@
-package org.apache.fulcrum.security.torque.dynamic;
-/*
- *  Copyright 2001-2004 The Apache Software Foundation
- *
- *  Licensed 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.
- */
-import java.sql.Connection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.fulcrum.security.entity.Group;
-import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
-import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicGroup;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicUser;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicUserDelegates;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicUserDelegatesPeer;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroup;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroupPeer;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicUserPeer;
-import org.apache.fulcrum.security.util.GroupSet;
-import org.apache.torque.TorqueException;
-import org.apache.torque.om.SimpleKey;
-import org.apache.torque.util.Criteria;
-/**
- * This abstract class provides the SecurityInterface to the managers.
- *
- * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
- * @version $Id:$
- */
-public abstract class TorqueAbstractDynamicUser extends TorqueAbstractSecurityEntity
-    implements DynamicUser
-{
-    /** a cache of group objects */
-    private Set groupSet = null;
-    
-    /** a cache of delegator (user) objects */
-    private Set delegators = null;
-
-    /** a cache of delegatee(user) objects */
-    private Set delegatees = null;
-
-    /**
-     * Forward reference to generated code
-     * 
-     * Get a list of association objects, pre-populated with their TorqueDynamicGroup 
-     * objects.
-     * 
-     * @param criteria Criteria to define the selection of records
-     * @throws TorqueException
-     * 
-     * @return a list of User/Group relations
-     */
-    protected abstract List getTorqueDynamicUserGroupsJoinTorqueDynamicGroup(Criteria criteria) 
-        throws TorqueException;
-    
-    /**
-     * Forward reference to generated code
-     * 
-     * Get a list of delegator association objects, pre-populated with their 
-     * TorqueDynamicUserDelegates objects.
-     * 
-     * @param criteria Criteria to define the selection of records
-     * @throws TorqueException
-     * 
-     * @return a list of User/Delegator relations
-     */
-    protected abstract List getTorqueDynamicUserDelegatessRelatedByDelegateeUserIdJoinTorqueDynamicUserRelatedByDelegatorUserId(Criteria criteria) 
-        throws TorqueException;
-    
-    /**
-     * Forward reference to generated code
-     * 
-     * Get a list of delegatee association objects, pre-populated with their 
-     * TorqueDynamicUserDelegates objects.
-     * 
-     * @param criteria Criteria to define the selection of records
-     * @throws TorqueException
-     * 
-     * @return a list of User/Delegator relations
-     */
-    protected abstract List getTorqueDynamicUserDelegatessRelatedByDelegatorUserIdJoinTorqueDynamicUserRelatedByDelegateeUserId(Criteria criteria) 
-        throws TorqueException;
-    
-    /**
-     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#addGroup(org.apache.fulcrum.security.entity.Group)
-     */
-    public void addGroup(Group group)
-    {
-        getGroups().add(group);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroups()
-     */
-    public GroupSet getGroups()
-    {
-        if (groupSet == null)
-        {
-            groupSet = new GroupSet();
-        }
-        else if(!(groupSet instanceof GroupSet))
-        {
-            groupSet = new GroupSet(groupSet);
-        }
-
-        return (GroupSet)groupSet;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroupsAsSet()
-     */
-    public Set getGroupsAsSet()
-    {
-        return groupSet;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#removeGroup(org.apache.fulcrum.security.entity.Group)
-     */
-    public void removeGroup(Group group)
-    {
-        getGroups().remove(group);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroups(org.apache.fulcrum.security.util.GroupSet)
-     */
-    public void setGroups(GroupSet groups)
-    {
-        if (groups != null)
-        {
-            this.groupSet = groups;
-        }
-        else
-        {
-            this.groupSet = new GroupSet();
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroupsAsSet(java.util.Set)
-     */
-    public void setGroupsAsSet(Set groups)
-    {
-        setGroups(new GroupSet(groups));
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#getDelegatees()
-     */
-    public Set getDelegatees()
-    {
-        if (delegatees == null)
-        {
-            delegatees = new HashSet();
-        }
-
-        return delegatees;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#getDelegators()
-     */
-    public Set getDelegators()
-    {
-        if (delegators == null)
-        {
-            delegators = new HashSet();
-        }
-
-        return delegators;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#setDelegatees(java.util.Set)
-     */
-    public void setDelegatees(Set delegatees)
-    {
-        if (delegatees != null)
-        {
-            this.delegatees = delegatees;
-        }
-        else
-        {
-            this.delegatees = new HashSet();
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#setDelegators(java.util.Set)
-     */
-    public void setDelegators(Set delegates)
-    {
-        if (delegators != null)
-        {
-            this.delegators = delegates;
-        }
-        else
-        {
-            this.delegators = new HashSet();
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
-     */
-    public String getDatabaseName()
-    {
-        return TorqueDynamicUserPeer.DATABASE_NAME;
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
-     */
-    public void retrieveAttachedObjects(Connection con) throws TorqueException
-    {
-        this.groupSet = new GroupSet();
-        
-        List usergroups = getTorqueDynamicUserGroupsJoinTorqueDynamicGroup(new Criteria());
-
-        for (Iterator i = usergroups.iterator(); i.hasNext();)
-        {
-            TorqueDynamicUserGroup tdug = (TorqueDynamicUserGroup)i.next(); 
-            groupSet.add(tdug.getTorqueDynamicGroup());
-        }
-
-        this.delegators = new HashSet();
-        
-        List delegatorlist = getTorqueDynamicUserDelegatessRelatedByDelegateeUserIdJoinTorqueDynamicUserRelatedByDelegatorUserId(new Criteria());
-
-        for (Iterator i = delegatorlist.iterator(); i.hasNext();)
-        {
-            TorqueDynamicUserDelegates tdud = (TorqueDynamicUserDelegates)i.next(); 
-            delegators.add(tdud.getTorqueDynamicUserRelatedByDelegatorUserId());
-        }
-
-        this.delegatees = new HashSet();
-        
-        List delegateelist = getTorqueDynamicUserDelegatessRelatedByDelegatorUserIdJoinTorqueDynamicUserRelatedByDelegateeUserId(new Criteria());
-
-        for (Iterator i = delegateelist.iterator(); i.hasNext();)
-        {
-            TorqueDynamicUserDelegates tdud = (TorqueDynamicUserDelegates)i.next(); 
-            delegatees.add(tdud.getTorqueDynamicUserRelatedByDelegateeUserId());
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
-     */
-    public void update(Connection con) throws TorqueException
-    {
-        if (groupSet != null)
-        {
-            Criteria criteria = new Criteria();
-            
-            /* remove old entries */
-            criteria.add(TorqueDynamicUserGroupPeer.USER_ID, getEntityId());
-            TorqueDynamicUserGroupPeer.doDelete(criteria, con);
-
-            for (Iterator i = groupSet.iterator(); i.hasNext();)
-            {
-                TorqueDynamicGroup group = (TorqueDynamicGroup)i.next();
-
-                TorqueDynamicUserGroup ug = new TorqueDynamicUserGroup();
-                ug.setUserId(getEntityId());
-                ug.setGroupId(group.getEntityId());
-                ug.save(con);
-            }
-        }
-        
-        if (delegators != null)
-        {
-            Criteria criteria = new Criteria();
-            
-            /* remove old entries */
-            criteria.add(TorqueDynamicUserDelegatesPeer.DELEGATEE_USER_ID, getEntityId());
-            TorqueDynamicUserDelegatesPeer.doDelete(criteria, con);
-
-            for (Iterator i = delegators.iterator(); i.hasNext();)
-            {
-                TorqueDynamicUser user = (TorqueDynamicUser)i.next();
-
-                TorqueDynamicUserDelegates ud = new TorqueDynamicUserDelegates();
-                ud.setDelegateeUserId(getEntityId());
-                ud.setDelegatorUserId(user.getEntityId());
-                ud.save(con);
-            }
-        }
-        
-        if (delegatees != null)
-        {
-            Criteria criteria = new Criteria();
-            
-            /* remove old entries */
-            criteria.add(TorqueDynamicUserDelegatesPeer.DELEGATOR_USER_ID, getEntityId());
-            TorqueDynamicUserDelegatesPeer.doDelete(criteria, con);
-
-            for (Iterator i = delegatees.iterator(); i.hasNext();)
-            {
-                TorqueDynamicUser user = (TorqueDynamicUser)i.next();
-
-                TorqueDynamicUserDelegates ud = new TorqueDynamicUserDelegates();
-                ud.setDelegatorUserId(getEntityId());
-                ud.setDelegateeUserId(user.getEntityId());
-                ud.save(con);
-            }
-        }
-
-        try
-        {
-            save(con);
-        }
-        catch (Exception e)
-        {
-            throw new TorqueException(e);
-        }
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
-     */
-    public void delete() throws TorqueException
-    {
-        TorqueDynamicUserPeer.doDelete(SimpleKey.keyFor(getEntityId()));
-    }
-}
\ No newline at end of file
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * 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.
+ */
+import java.sql.Connection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroup;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUser;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserDelegates;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserDelegatesPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroup;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserGroupPeer;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicUserPeer;
+import org.apache.fulcrum.security.util.GroupSet;
+import org.apache.torque.TorqueException;
+import org.apache.torque.om.SimpleKey;
+import org.apache.torque.util.Criteria;
+/**
+ * This abstract class provides the SecurityInterface to the managers.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public abstract class TorqueAbstractDynamicUser extends TorqueAbstractSecurityEntity
+    implements DynamicUser
+{
+    /** a cache of group objects */
+    private Set groupSet = null;
+
+    /** a cache of delegator (user) objects */
+    private Set delegators = null;
+
+    /** a cache of delegatee(user) objects */
+    private Set delegatees = null;
+
+    /**
+     * Forward reference to generated code
+     *
+     * Get a list of association objects, pre-populated with their TorqueDynamicGroup
+     * objects.
+     *
+     * @param criteria Criteria to define the selection of records
+     * @throws TorqueException
+     *
+     * @return a list of User/Group relations
+     */
+    protected abstract List getTorqueDynamicUserGroupsJoinTorqueDynamicGroup(Criteria criteria)
+        throws TorqueException;
+
+    /**
+     * Forward reference to generated code
+     *
+     * Get a list of delegator association objects, pre-populated with their
+     * TorqueDynamicUserDelegates objects.
+     *
+     * @param criteria Criteria to define the selection of records
+     * @throws TorqueException
+     *
+     * @return a list of User/Delegator relations
+     */
+    protected abstract List getTorqueDynamicUserDelegatessRelatedByDelegateeUserIdJoinTorqueDynamicUserRelatedByDelegatorUserId(Criteria criteria)
+        throws TorqueException;
+
+    /**
+     * Forward reference to generated code
+     *
+     * Get a list of delegatee association objects, pre-populated with their
+     * TorqueDynamicUserDelegates objects.
+     *
+     * @param criteria Criteria to define the selection of records
+     * @throws TorqueException
+     *
+     * @return a list of User/Delegator relations
+     */
+    protected abstract List getTorqueDynamicUserDelegatessRelatedByDelegatorUserIdJoinTorqueDynamicUserRelatedByDelegateeUserId(Criteria criteria)
+        throws TorqueException;
+
+    /**
+     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#addGroup(org.apache.fulcrum.security.entity.Group)
+     */
+    public void addGroup(Group group)
+    {
+        getGroups().add(group);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroups()
+     */
+    public GroupSet getGroups()
+    {
+        if (groupSet == null)
+        {
+            groupSet = new GroupSet();
+        }
+        else if(!(groupSet instanceof GroupSet))
+        {
+            groupSet = new GroupSet(groupSet);
+        }
+
+        return (GroupSet)groupSet;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#getGroupsAsSet()
+     */
+    public Set getGroupsAsSet()
+    {
+        return groupSet;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#removeGroup(org.apache.fulcrum.security.entity.Group)
+     */
+    public void removeGroup(Group group)
+    {
+        getGroups().remove(group);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroups(org.apache.fulcrum.security.util.GroupSet)
+     */
+    public void setGroups(GroupSet groups)
+    {
+        if (groups != null)
+        {
+            this.groupSet = groups;
+        }
+        else
+        {
+            this.groupSet = new GroupSet();
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.basic.entity.BasicUser#setGroupsAsSet(java.util.Set)
+     */
+    public void setGroupsAsSet(Set groups)
+    {
+        setGroups(new GroupSet(groups));
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#getDelegatees()
+     */
+    public Set getDelegatees()
+    {
+        if (delegatees == null)
+        {
+            delegatees = new HashSet();
+        }
+
+        return delegatees;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#getDelegators()
+     */
+    public Set getDelegators()
+    {
+        if (delegators == null)
+        {
+            delegators = new HashSet();
+        }
+
+        return delegators;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#setDelegatees(java.util.Set)
+     */
+    public void setDelegatees(Set delegatees)
+    {
+        if (delegatees != null)
+        {
+            this.delegatees = delegatees;
+        }
+        else
+        {
+            this.delegatees = new HashSet();
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.model.dynamic.entity.DynamicUser#setDelegators(java.util.Set)
+     */
+    public void setDelegators(Set delegates)
+    {
+        if (delegators != null)
+        {
+            this.delegators = delegates;
+        }
+        else
+        {
+            this.delegators = new HashSet();
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#getDatabaseName()
+     */
+    public String getDatabaseName()
+    {
+        return TorqueDynamicUserPeer.DATABASE_NAME;
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#retrieveAttachedObjects(java.sql.Connection)
+     */
+    public void retrieveAttachedObjects(Connection con) throws TorqueException
+    {
+        this.groupSet = new GroupSet();
+
+        List usergroups = getTorqueDynamicUserGroupsJoinTorqueDynamicGroup(new Criteria());
+
+        for (Iterator i = usergroups.iterator(); i.hasNext();)
+        {
+            TorqueDynamicUserGroup tdug = (TorqueDynamicUserGroup)i.next();
+            groupSet.add(tdug.getTorqueDynamicGroup());
+        }
+
+        this.delegators = new HashSet();
+
+        List delegatorlist = getTorqueDynamicUserDelegatessRelatedByDelegateeUserIdJoinTorqueDynamicUserRelatedByDelegatorUserId(new Criteria());
+
+        for (Iterator i = delegatorlist.iterator(); i.hasNext();)
+        {
+            TorqueDynamicUserDelegates tdud = (TorqueDynamicUserDelegates)i.next();
+            delegators.add(tdud.getTorqueDynamicUserRelatedByDelegatorUserId());
+        }
+
+        this.delegatees = new HashSet();
+
+        List delegateelist = getTorqueDynamicUserDelegatessRelatedByDelegatorUserIdJoinTorqueDynamicUserRelatedByDelegateeUserId(new Criteria());
+
+        for (Iterator i = delegateelist.iterator(); i.hasNext();)
+        {
+            TorqueDynamicUserDelegates tdud = (TorqueDynamicUserDelegates)i.next();
+            delegatees.add(tdud.getTorqueDynamicUserRelatedByDelegateeUserId());
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#update(java.sql.Connection)
+     */
+    public void update(Connection con) throws TorqueException
+    {
+        if (groupSet != null)
+        {
+            Criteria criteria = new Criteria();
+
+            /* remove old entries */
+            criteria.add(TorqueDynamicUserGroupPeer.USER_ID, getEntityId());
+            TorqueDynamicUserGroupPeer.doDelete(criteria, con);
+
+            for (Iterator i = groupSet.iterator(); i.hasNext();)
+            {
+                TorqueDynamicGroup group = (TorqueDynamicGroup)i.next();
+
+                TorqueDynamicUserGroup ug = new TorqueDynamicUserGroup();
+                ug.setUserId(getEntityId());
+                ug.setGroupId(group.getEntityId());
+                ug.save(con);
+            }
+        }
+
+        if (delegators != null)
+        {
+            Criteria criteria = new Criteria();
+
+            /* remove old entries */
+            criteria.add(TorqueDynamicUserDelegatesPeer.DELEGATEE_USER_ID, getEntityId());
+            TorqueDynamicUserDelegatesPeer.doDelete(criteria, con);
+
+            for (Iterator i = delegators.iterator(); i.hasNext();)
+            {
+                TorqueDynamicUser user = (TorqueDynamicUser)i.next();
+
+                TorqueDynamicUserDelegates ud = new TorqueDynamicUserDelegates();
+                ud.setDelegateeUserId(getEntityId());
+                ud.setDelegatorUserId(user.getEntityId());
+                ud.save(con);
+            }
+        }
+
+        if (delegatees != null)
+        {
+            Criteria criteria = new Criteria();
+
+            /* remove old entries */
+            criteria.add(TorqueDynamicUserDelegatesPeer.DELEGATOR_USER_ID, getEntityId());
+            TorqueDynamicUserDelegatesPeer.doDelete(criteria, con);
+
+            for (Iterator i = delegatees.iterator(); i.hasNext();)
+            {
+                TorqueDynamicUser user = (TorqueDynamicUser)i.next();
+
+                TorqueDynamicUserDelegates ud = new TorqueDynamicUserDelegates();
+                ud.setDelegatorUserId(getEntityId());
+                ud.setDelegateeUserId(user.getEntityId());
+                ud.save(con);
+            }
+        }
+
+        try
+        {
+            save(con);
+        }
+        catch (Exception e)
+        {
+            throw new TorqueException(e);
+        }
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity#delete()
+     */
+    public void delete() throws TorqueException
+    {
+        TorqueDynamicUserPeer.doDelete(SimpleKey.keyFor(getEntityId()));
+    }
+}

Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java?view=diff&rev=535465&r1=535464&r2=535465
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicGroupManagerImpl.java Fri May  4 23:58:06 2007
@@ -1,72 +1,75 @@
-package org.apache.fulcrum.security.torque.dynamic;
-/*
- *  Copyright 2001-2004 The Apache Software Foundation
- *
- *  Licensed 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.
- */
-import java.sql.Connection;
-import java.util.List;
-
-import org.apache.fulcrum.security.entity.Group;
-import org.apache.fulcrum.security.torque.TorqueAbstractGroupManager;
-import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupPeer;
-import org.apache.torque.NoRowsException;
-import org.apache.torque.TooManyRowsException;
-import org.apache.torque.TorqueException;
-import org.apache.torque.util.Criteria;
-/**
- * This implementation persists to a database via Torque.
- *
- * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
- * @version $Id:$
- */
-public class TorqueDynamicGroupManagerImpl extends TorqueAbstractGroupManager
-{
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectAllGroups(java.sql.Connection)
-     */
-    protected List doSelectAllGroups(Connection con) throws TorqueException
-    {
-        Criteria criteria = new Criteria(TorqueDynamicGroupPeer.DATABASE_NAME);
-        
-        return TorqueDynamicGroupPeer.doSelect(criteria, con);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectById(java.lang.Integer, java.sql.Connection)
-     */
-    protected Group doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
-    {
-        return TorqueDynamicGroupPeer.retrieveByPK(id, con);
-    }
-
-    /**
-     * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectByName(java.lang.String, java.sql.Connection)
-     */
-    protected Group doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
-    {
-        Criteria criteria = new Criteria(TorqueDynamicGroupPeer.DATABASE_NAME);
-        criteria.add(TorqueDynamicGroupPeer.GROUP_NAME, name);
-        criteria.setIgnoreCase(true);
-        criteria.setSingleRecord(true);
-        
-        List groups = TorqueDynamicGroupPeer.doSelect(criteria, con);
-
-        if (groups.isEmpty())
-        {
-            throw new NoRowsException(name);
-        }
-        
-        return (Group)groups.get(0);
-    }
-}
\ No newline at end of file
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * 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.
+ */
+import java.sql.Connection;
+import java.util.List;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.torque.TorqueAbstractGroupManager;
+import org.apache.fulcrum.security.torque.om.TorqueDynamicGroupPeer;
+import org.apache.torque.NoRowsException;
+import org.apache.torque.TooManyRowsException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.util.Criteria;
+/**
+ * This implementation persists to a database via Torque.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public class TorqueDynamicGroupManagerImpl extends TorqueAbstractGroupManager
+{
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectAllGroups(java.sql.Connection)
+     */
+    protected List doSelectAllGroups(Connection con) throws TorqueException
+    {
+        Criteria criteria = new Criteria(TorqueDynamicGroupPeer.DATABASE_NAME);
+
+        return TorqueDynamicGroupPeer.doSelect(criteria, con);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectById(java.lang.Integer, java.sql.Connection)
+     */
+    protected Group doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
+    {
+        return TorqueDynamicGroupPeer.retrieveByPK(id, con);
+    }
+
+    /**
+     * @see org.apache.fulcrum.security.torque.TorqueAbstractGroupManager#doSelectByName(java.lang.String, java.sql.Connection)
+     */
+    protected Group doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException
+    {
+        Criteria criteria = new Criteria(TorqueDynamicGroupPeer.DATABASE_NAME);
+        criteria.add(TorqueDynamicGroupPeer.GROUP_NAME, name);
+        criteria.setIgnoreCase(true);
+        criteria.setSingleRecord(true);
+
+        List groups = TorqueDynamicGroupPeer.doSelect(criteria, con);
+
+        if (groups.isEmpty())
+        {
+            throw new NoRowsException(name);
+        }
+
+        return (Group)groups.get(0);
+    }
+}

Modified: jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerImpl.java
URL: http://svn.apache.org/viewvc/jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerImpl.java?view=diff&rev=535465&r1=535464&r2=535465
==============================================================================
--- jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerImpl.java (original)
+++ jakarta/turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/dynamic/TorqueDynamicModelManagerImpl.java Fri May  4 23:58:06 2007
@@ -1,493 +1,496 @@
-package org.apache.fulcrum.security.torque.dynamic;
-/*
- *  Copyright 2001-2004 The Apache Software Foundation
- *
- *  Licensed 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.
- */
-import java.sql.Connection;
-
-import org.apache.fulcrum.security.entity.Group;
-import org.apache.fulcrum.security.entity.Permission;
-import org.apache.fulcrum.security.entity.Role;
-import org.apache.fulcrum.security.entity.User;
-import org.apache.fulcrum.security.model.dynamic.AbstractDynamicModelManager;
-import org.apache.fulcrum.security.model.dynamic.DynamicModelManager;
-import org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup;
-import org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission;
-import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
-import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
-import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
-import org.apache.fulcrum.security.util.DataBackendException;
-import org.apache.fulcrum.security.util.UnknownEntityException;
-import org.apache.torque.TorqueException;
-import org.apache.torque.util.Transaction;
-/**
- * This implementation persists to a database via Torque.
- *
- * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
- * @version $Id:$
- */
-public class TorqueDynamicModelManagerImpl extends AbstractDynamicModelManager implements DynamicModelManager
-{
-    /**
-     * Revokes a Role from a Group.
-     *
-     * @param group the Group.
-     * @param role the Role.
-     * @throws DataBackendException if there was an error accessing the data backend.
-     * @throws UnknownEntityException if group or role is not present.
-     */
-    public synchronized void revoke(Group group, Role role)
-        throws DataBackendException, UnknownEntityException
-    {
-        boolean groupExists = getGroupManager().checkExists(group);
-        boolean roleExists = getRoleManager().checkExists(role);
-
-        if (groupExists && roleExists)
-        {
-            ((DynamicGroup) group).removeRole(role);
-            ((DynamicRole) role).removeGroup(group);
-
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)role).update(con);
-                ((TorqueAbstractSecurityEntity)group).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("revoke('" + group.getName() + "', '" + role.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-            
-            return;
-        }
-
-        if (!groupExists)
-        {
-            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
-        }
-
-        if (!roleExists)
-        {
-            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
-        }
-    }
-
-    /**
-     * Grants a Role a Permission
-     *
-     * @param role the Role.
-     * @param permission the Permission.
-     * @throws DataBackendException if there was an error accessing the data backend.
-     * @throws UnknownEntityException if role or permission is not present.
-     */
-    public synchronized void grant(Role role, Permission permission)
-        throws DataBackendException, UnknownEntityException
-    {
-        boolean roleExists = getRoleManager().checkExists(role);
-        boolean permissionExists = getPermissionManager().checkExists(permission);
-
-        if (roleExists && permissionExists)
-        {
-            ((DynamicRole) role).addPermission(permission);
-            ((DynamicPermission) permission).addRole(role);
-
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)role).update(con);
-                ((TorqueAbstractSecurityEntity)permission).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("grant('" + role.getName() + "', '" + permission.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-            
-            return;
-        }
-
-        if (!roleExists)
-        {
-            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
-        }
-
-        if (!permissionExists)
-        {
-            throw new UnknownEntityException("Unknown permission '" + permission.getName() + "'");
-        }
-    }
-    
-    /**
-     * Revokes a Permission from a Role.
-     *
-     * @param role the Role.
-     * @param permission the Permission.
-     * @throws DataBackendException if there was an error accessing the data backend.
-     * @throws UnknownEntityException if role or permission is not present.
-     */
-    public synchronized void revoke(Role role, Permission permission)
-        throws DataBackendException, UnknownEntityException
-    {
-        boolean roleExists = getRoleManager().checkExists(role);
-        boolean permissionExists = getPermissionManager().checkExists(permission);
-
-        if (roleExists && permissionExists)
-        {
-            ((DynamicRole) role).removePermission(permission);
-            ((DynamicPermission) permission).removeRole(role);
-
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)role).update(con);
-                ((TorqueAbstractSecurityEntity)permission).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("revoke('" + role.getName() + "', '" + permission.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-            
-            return;
-        }
-        
-        if (!roleExists)
-        {
-            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
-        }
-        
-        if (!permissionExists)
-        {
-            throw new UnknownEntityException("Unknown permission '" + permission.getName() + "'");
-        }
-    }
-
-    /**
-     * Puts a user in a group.
-     *
-     * This method is used when adding a user to a group
-     *
-     * @param user the User.
-     * @throws DataBackendException if there was an error accessing the data backend.
-     * @throws UnknownEntityException if the account is not present.
-     */
-    public synchronized void grant(User user, Group group) throws DataBackendException, UnknownEntityException
-    {
-        boolean groupExists = getGroupManager().checkExists(group);
-        boolean userExists = getUserManager().checkExists(user);
-        
-        if (groupExists && userExists)
-        {
-            ((DynamicUser) user).addGroup(group);
-            ((DynamicGroup) group).addUser(user);
-            
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)user).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)user).update(con);
-                ((TorqueAbstractSecurityEntity)group).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("grant('" + user.getName() + "', '" + group.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-
-            return;
-        }
-
-        if (!groupExists)
-        {
-            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
-        }
-
-        if (!userExists)
-        {
-            throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
-        }
-    }
-
-    /**
-     * Removes a user in a group.
-     *
-     * This method is used when removing a user to a group
-     *
-     * @param user the User.
-     * @throws DataBackendException if there was an error accessing the data backend.
-     * @throws UnknownEntityException if the user or group is not present.
-     */
-    public synchronized void revoke(User user, Group group) throws DataBackendException, UnknownEntityException
-    {
-        boolean groupExists = getGroupManager().checkExists(group);
-        boolean userExists = getUserManager().checkExists(user);
-        
-        if (groupExists && userExists)
-        {
-            ((DynamicUser) user).removeGroup(group);
-            ((DynamicGroup) group).removeUser(user);
-            
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)user).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)user).update(con);
-                ((TorqueAbstractSecurityEntity)group).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("revoke('" + user.getName() + "', '" + group.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-
-            return;
-        }
-
-        if (!groupExists)
-        {
-            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
-        }
-
-        if (!userExists)
-        {
-            throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
-        }
-    }
-
-    /**
-     * Grants a Group a Role
-     *
-     * @param group the Group.
-     * @param role the Role.
-     * @throws DataBackendException if there was an error accessing the data backend.
-     * @throws UnknownEntityException if group or role is not present.
-     */
-    public synchronized void grant(Group group, Role role)
-        throws DataBackendException, UnknownEntityException
-    {
-        boolean groupExists = getGroupManager().checkExists(group);
-        boolean roleExists = getRoleManager().checkExists(role);
-        
-        if (groupExists && roleExists)
-        {
-            ((DynamicGroup) group).addRole(role);
-            ((DynamicRole) role).addGroup(group);
-            
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)role).update(con);
-                ((TorqueAbstractSecurityEntity)group).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("grant('" + group.getName() + "', '" + role.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-            
-            return;
-        }
-
-        if (!groupExists)
-        {
-            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
-        }
-
-        if (!roleExists)
-        {
-            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
-        }
-    }
-
-    /**
-     * Allow B to assumes A's roles, groups and permissions
-     * @param delegator A
-     * @param delegatee B
-     */
-    public synchronized void addDelegate(User delegator, User delegatee)
-            throws DataBackendException, UnknownEntityException 
-    {
-        boolean delegatorExists = getUserManager().checkExists(delegator);
-        boolean delegateeExists = getUserManager().checkExists(delegatee);
-        
-        if (delegatorExists && delegateeExists)
-        {
-            super.addDelegate(delegator, delegatee);
-
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)delegator).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)delegator).update(con);
-                ((TorqueAbstractSecurityEntity)delegatee).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("addDelegate('" 
-                        + delegator.getName() + "', '" 
-                        + delegatee.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-            
-            return;
-        }
-
-        if (!delegatorExists)
-        {
-            throw new UnknownEntityException("Unknown user '" + delegator.getName() + "'");
-        }
-
-        if (!delegateeExists)
-        {
-            throw new UnknownEntityException("Unknown user '" + delegatee.getName() + "'");
-        }
-    }
-
-    /**
-     * Stop A having B's roles, groups and permissions
-     * @param delegate A
-     * @param delegatee B
-     */
-    public synchronized void removeDelegate(User delegator, User delegatee)
-            throws DataBackendException, UnknownEntityException 
-    {
-        boolean delegatorExists = getUserManager().checkExists(delegator);
-        boolean delegateeExists = getUserManager().checkExists(delegatee);
-        
-        if (delegatorExists && delegateeExists)
-        {
-            super.removeDelegate(delegator, delegatee);
-
-            Connection con = null;
-            
-            try
-            {
-                con = Transaction.begin(((TorqueAbstractSecurityEntity)delegator).getDatabaseName());
-                
-                ((TorqueAbstractSecurityEntity)delegator).update(con);
-                ((TorqueAbstractSecurityEntity)delegatee).update(con);
-                
-                Transaction.commit(con);
-                con = null;
-            }
-            catch (TorqueException e)
-            {
-                throw new DataBackendException("removeDelegate('" 
-                        + delegator.getName() + "', '" 
-                        + delegatee.getName() + "') failed", e);
-            }
-            finally
-            {
-                if (con != null)
-                {
-                    Transaction.safeRollback(con);
-                }
-            }
-            
-            return;
-        }
-
-        if (!delegatorExists)
-        {
-            throw new UnknownEntityException("Unknown user '" + delegator.getName() + "'");
-        }
-
-        if (!delegateeExists)
-        {
-            throw new UnknownEntityException("Unknown user '" + delegatee.getName() + "'");
-        }
-    }
-}
\ No newline at end of file
+package org.apache.fulcrum.security.torque.dynamic;
+/*
+ * 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.
+ */
+import java.sql.Connection;
+
+import org.apache.fulcrum.security.entity.Group;
+import org.apache.fulcrum.security.entity.Permission;
+import org.apache.fulcrum.security.entity.Role;
+import org.apache.fulcrum.security.entity.User;
+import org.apache.fulcrum.security.model.dynamic.AbstractDynamicModelManager;
+import org.apache.fulcrum.security.model.dynamic.DynamicModelManager;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicRole;
+import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
+import org.apache.fulcrum.security.torque.TorqueAbstractSecurityEntity;
+import org.apache.fulcrum.security.util.DataBackendException;
+import org.apache.fulcrum.security.util.UnknownEntityException;
+import org.apache.torque.TorqueException;
+import org.apache.torque.util.Transaction;
+/**
+ * This implementation persists to a database via Torque.
+ *
+ * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
+ * @version $Id:$
+ */
+public class TorqueDynamicModelManagerImpl extends AbstractDynamicModelManager implements DynamicModelManager
+{
+    /**
+     * Revokes a Role from a Group.
+     *
+     * @param group the Group.
+     * @param role the Role.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if group or role is not present.
+     */
+    public synchronized void revoke(Group group, Role role)
+        throws DataBackendException, UnknownEntityException
+    {
+        boolean groupExists = getGroupManager().checkExists(group);
+        boolean roleExists = getRoleManager().checkExists(role);
+
+        if (groupExists && roleExists)
+        {
+            ((DynamicGroup) group).removeRole(role);
+            ((DynamicRole) role).removeGroup(group);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)role).update(con);
+                ((TorqueAbstractSecurityEntity)group).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("revoke('" + group.getName() + "', '" + role.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!groupExists)
+        {
+            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
+        }
+
+        if (!roleExists)
+        {
+            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
+        }
+    }
+
+    /**
+     * Grants a Role a Permission
+     *
+     * @param role the Role.
+     * @param permission the Permission.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if role or permission is not present.
+     */
+    public synchronized void grant(Role role, Permission permission)
+        throws DataBackendException, UnknownEntityException
+    {
+        boolean roleExists = getRoleManager().checkExists(role);
+        boolean permissionExists = getPermissionManager().checkExists(permission);
+
+        if (roleExists && permissionExists)
+        {
+            ((DynamicRole) role).addPermission(permission);
+            ((DynamicPermission) permission).addRole(role);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)role).update(con);
+                ((TorqueAbstractSecurityEntity)permission).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("grant('" + role.getName() + "', '" + permission.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!roleExists)
+        {
+            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
+        }
+
+        if (!permissionExists)
+        {
+            throw new UnknownEntityException("Unknown permission '" + permission.getName() + "'");
+        }
+    }
+
+    /**
+     * Revokes a Permission from a Role.
+     *
+     * @param role the Role.
+     * @param permission the Permission.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if role or permission is not present.
+     */
+    public synchronized void revoke(Role role, Permission permission)
+        throws DataBackendException, UnknownEntityException
+    {
+        boolean roleExists = getRoleManager().checkExists(role);
+        boolean permissionExists = getPermissionManager().checkExists(permission);
+
+        if (roleExists && permissionExists)
+        {
+            ((DynamicRole) role).removePermission(permission);
+            ((DynamicPermission) permission).removeRole(role);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)role).update(con);
+                ((TorqueAbstractSecurityEntity)permission).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("revoke('" + role.getName() + "', '" + permission.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!roleExists)
+        {
+            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
+        }
+
+        if (!permissionExists)
+        {
+            throw new UnknownEntityException("Unknown permission '" + permission.getName() + "'");
+        }
+    }
+
+    /**
+     * Puts a user in a group.
+     *
+     * This method is used when adding a user to a group
+     *
+     * @param user the User.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if the account is not present.
+     */
+    public synchronized void grant(User user, Group group) throws DataBackendException, UnknownEntityException
+    {
+        boolean groupExists = getGroupManager().checkExists(group);
+        boolean userExists = getUserManager().checkExists(user);
+
+        if (groupExists && userExists)
+        {
+            ((DynamicUser) user).addGroup(group);
+            ((DynamicGroup) group).addUser(user);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)user).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)user).update(con);
+                ((TorqueAbstractSecurityEntity)group).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("grant('" + user.getName() + "', '" + group.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!groupExists)
+        {
+            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
+        }
+
+        if (!userExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
+        }
+    }
+
+    /**
+     * Removes a user in a group.
+     *
+     * This method is used when removing a user to a group
+     *
+     * @param user the User.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if the user or group is not present.
+     */
+    public synchronized void revoke(User user, Group group) throws DataBackendException, UnknownEntityException
+    {
+        boolean groupExists = getGroupManager().checkExists(group);
+        boolean userExists = getUserManager().checkExists(user);
+
+        if (groupExists && userExists)
+        {
+            ((DynamicUser) user).removeGroup(group);
+            ((DynamicGroup) group).removeUser(user);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)user).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)user).update(con);
+                ((TorqueAbstractSecurityEntity)group).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("revoke('" + user.getName() + "', '" + group.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!groupExists)
+        {
+            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
+        }
+
+        if (!userExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + user.getName() + "'");
+        }
+    }
+
+    /**
+     * Grants a Group a Role
+     *
+     * @param group the Group.
+     * @param role the Role.
+     * @throws DataBackendException if there was an error accessing the data backend.
+     * @throws UnknownEntityException if group or role is not present.
+     */
+    public synchronized void grant(Group group, Role role)
+        throws DataBackendException, UnknownEntityException
+    {
+        boolean groupExists = getGroupManager().checkExists(group);
+        boolean roleExists = getRoleManager().checkExists(role);
+
+        if (groupExists && roleExists)
+        {
+            ((DynamicGroup) group).addRole(role);
+            ((DynamicRole) role).addGroup(group);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)role).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)role).update(con);
+                ((TorqueAbstractSecurityEntity)group).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("grant('" + group.getName() + "', '" + role.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!groupExists)
+        {
+            throw new UnknownEntityException("Unknown group '" + group.getName() + "'");
+        }
+
+        if (!roleExists)
+        {
+            throw new UnknownEntityException("Unknown role '" + role.getName() + "'");
+        }
+    }
+
+    /**
+     * Allow B to assumes A's roles, groups and permissions
+     * @param delegator A
+     * @param delegatee B
+     */
+    public synchronized void addDelegate(User delegator, User delegatee)
+            throws DataBackendException, UnknownEntityException
+    {
+        boolean delegatorExists = getUserManager().checkExists(delegator);
+        boolean delegateeExists = getUserManager().checkExists(delegatee);
+
+        if (delegatorExists && delegateeExists)
+        {
+            super.addDelegate(delegator, delegatee);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)delegator).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)delegator).update(con);
+                ((TorqueAbstractSecurityEntity)delegatee).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("addDelegate('"
+                        + delegator.getName() + "', '"
+                        + delegatee.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!delegatorExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + delegator.getName() + "'");
+        }
+
+        if (!delegateeExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + delegatee.getName() + "'");
+        }
+    }
+
+    /**
+     * Stop A having B's roles, groups and permissions
+     * @param delegate A
+     * @param delegatee B
+     */
+    public synchronized void removeDelegate(User delegator, User delegatee)
+            throws DataBackendException, UnknownEntityException
+    {
+        boolean delegatorExists = getUserManager().checkExists(delegator);
+        boolean delegateeExists = getUserManager().checkExists(delegatee);
+
+        if (delegatorExists && delegateeExists)
+        {
+            super.removeDelegate(delegator, delegatee);
+
+            Connection con = null;
+
+            try
+            {
+                con = Transaction.begin(((TorqueAbstractSecurityEntity)delegator).getDatabaseName());
+
+                ((TorqueAbstractSecurityEntity)delegator).update(con);
+                ((TorqueAbstractSecurityEntity)delegatee).update(con);
+
+                Transaction.commit(con);
+                con = null;
+            }
+            catch (TorqueException e)
+            {
+                throw new DataBackendException("removeDelegate('"
+                        + delegator.getName() + "', '"
+                        + delegatee.getName() + "') failed", e);
+            }
+            finally
+            {
+                if (con != null)
+                {
+                    Transaction.safeRollback(con);
+                }
+            }
+
+            return;
+        }
+
+        if (!delegatorExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + delegator.getName() + "'");
+        }
+
+        if (!delegateeExists)
+        {
+            throw new UnknownEntityException("Unknown user '" + delegatee.getName() + "'");
+        }
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org