1 package org.apache.fulcrum.security.impl.db.entity; 2 3 56 57 import java.util.Enumeration ; 58 import java.util.List ; 59 import java.util.Vector ; 60 61 import org.apache.fulcrum.security.entity.Permission; 62 import org.apache.fulcrum.security.entity.Role; 63 import org.apache.fulcrum.security.entity.SecurityEntity; 64 import org.apache.fulcrum.security.util.DataBackendException; 65 import org.apache.fulcrum.security.util.PermissionSet; 66 import org.apache.torque.om.BaseObject; 67 import org.apache.torque.util.BasePeer; 68 import org.apache.torque.util.Criteria; 69 70 81 public class TurbinePermissionPeer 82 extends org.apache.fulcrum.security.impl.db.entity.BaseTurbinePermissionPeer 83 { 84 85 public static final String NAME = PERMISSION_NAME; 86 87 97 public static boolean checkExists( Permission permission ) 98 throws DataBackendException, Exception 99 { 100 Criteria criteria = new Criteria(); 101 criteria.addSelectColumn(PERMISSION_ID); 102 criteria.add(NAME, ((SecurityEntity)permission).getName()); 103 List results = BasePeer.doSelect(criteria); 104 if (results.size() > 1) 105 { 106 throw new DataBackendException("Multiple permissions named '" + 107 ((SecurityEntity)permission).getName() + "' exist!"); 108 } 109 return (results.size()==1); 110 } 111 112 117 public static String getColumnName (String name) 118 { 119 StringBuffer sb = new StringBuffer (); 120 sb.append(TurbinePermissionPeer.TABLE_NAME); 121 sb.append("."); 122 sb.append(name); 123 return sb.toString(); 124 } 125 126 131 public static String getTableName() 132 { 133 return TABLE_NAME; 134 } 135 136 143 public static PermissionSet retrieveSet(Criteria criteria) 144 throws Exception 145 { 146 List results = doSelect(criteria); 147 PermissionSet ps = new PermissionSet(); 148 for (int i=0; i<results.size(); i++) 149 { 150 ps.add( (Permission)results.get(i) ); 151 } 152 return ps; 153 } 154 155 162 public static PermissionSet retrieveSet( Role role ) 163 throws Exception 164 { 165 Criteria criteria = new Criteria(); 166 criteria.add(TurbineRolePermissionPeer.ROLE_ID, 167 ((TurbineRole)role).getPrimaryKey()); 168 criteria.addJoin(TurbineRolePermissionPeer.PERMISSION_ID, 169 TurbinePermissionPeer.PERMISSION_ID); 170 return retrieveSet(criteria); 171 } 172 173 181 public static final Vector getDifference(Vector some, Vector all) 182 { 183 Vector clone = (Vector )all.clone(); 184 for (Enumeration e = some.elements() ; e.hasMoreElements() ;) 185 { 186 Permission tmp = (Permission) e.nextElement(); 187 for (Enumeration f = clone.elements() ; f.hasMoreElements() ;) 188 { 189 Permission tmp2 = (Permission) f.nextElement(); 190 if (((BaseObject)tmp).getPrimaryKey() == 191 ((BaseObject)tmp2).getPrimaryKey()) 192 { 193 clone.removeElement(tmp2); 194 break; 195 } 196 } 197 } 198 return clone; 199 } 200 201 } 202 | Popular Tags |