1 package org.enhydra.shark; 2 3 import java.util.List ; 4 5 import org.enhydra.shark.api.RootException; 6 import org.enhydra.shark.api.SharkTransaction; 7 import org.enhydra.shark.api.client.wfbase.BaseException; 8 import org.enhydra.shark.api.client.wfmodel.NotAssigned; 9 import org.enhydra.shark.api.client.wfmodel.WfAssignment; 10 import org.enhydra.shark.api.client.wfmodel.WfAssignmentIterator; 11 import org.enhydra.shark.api.client.wfmodel.WfResource; 12 import org.enhydra.shark.api.internal.security.SecurityManager; 13 import org.enhydra.shark.api.internal.working.WfResourceInternal; 14 15 20 public class WfResourceWrapper implements WfResource { 21 22 private String userAuth; 23 private String username; 24 25 29 protected WfResourceWrapper(String userAuth,String username) { 30 this.userAuth=userAuth; 31 this.username = username; 32 } 33 34 37 public int how_many_work_item () throws BaseException { 38 int ret = -1; 39 SharkTransaction t = null; 40 try { 41 t = SharkUtilities.createTransaction(); 42 ret = how_many_work_item(t); 43 } catch (RootException e) { 45 SharkUtilities.emptyCaches(t); 47 if (e instanceof BaseException) 48 throw (BaseException)e; 49 else 50 throw new BaseException(e); 51 } finally { 52 SharkUtilities.releaseTransaction(t); 53 } 54 return ret; 55 } 56 57 public int how_many_work_item (SharkTransaction t) throws BaseException { 58 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 59 if (sm!=null) { 60 try { 61 sm.check_resource_how_many_work_item(t, 62 username, 63 userAuth); 64 } catch (Exception ex) { 65 throw new BaseException(ex); 66 } 67 } 68 69 try { 70 return SharkEngineManager 71 .getInstance() 72 .getInstancePersistenceManager() 73 .getAllValidAssignmentsForResource(username,t).size(); 74 } catch (Exception e) { 75 throw new BaseException(e); 76 } 77 } 78 79 82 public WfAssignmentIterator get_iterator_work_item () throws BaseException { 83 WfAssignmentIterator ret = null; 84 SharkTransaction t = null; 85 try { 86 t = SharkUtilities.createTransaction(); 87 ret = get_iterator_work_item(t); 88 } catch (RootException e) { 90 SharkUtilities.emptyCaches(t); 92 if (e instanceof BaseException) 93 throw (BaseException)e; 94 else 95 throw new BaseException(e); 96 } finally { 97 SharkUtilities.releaseTransaction(t); 98 } 99 return ret; 100 } 101 102 public WfAssignmentIterator get_iterator_work_item (SharkTransaction t) 103 throws BaseException { 104 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 105 if (sm!=null) { 106 try { 107 sm.check_resource_get_iterator_work_item(t, 108 username, 109 userAuth); 110 } catch (Exception ex) { 111 throw new BaseException(ex); 112 } 113 } 114 115 116 return SharkEngineManager.getInstance().getObjectFactory().createAssignmentIteratorWrapper(t,userAuth,username); 117 } 118 119 123 public WfAssignment[] get_sequence_work_item (int max_number) throws BaseException { 124 WfAssignment[] ret = null; 125 SharkTransaction t = null; 126 try { 127 t = SharkUtilities.createTransaction(); 128 ret = get_sequence_work_item(t, max_number); 129 } catch (RootException e) { 131 SharkUtilities.emptyCaches(t); 133 if (e instanceof BaseException) 134 throw (BaseException)e; 135 else 136 throw new BaseException(e); 137 } finally { 138 SharkUtilities.releaseTransaction(t); 139 } 140 return ret; 141 } 142 143 public WfAssignment[] get_sequence_work_item(SharkTransaction t,int max_number) 144 throws BaseException { 145 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 146 if (sm!=null) { 147 try { 148 sm.check_resource_get_sequence_work_item(t, 149 username, 150 userAuth); 151 } catch (Exception ex) { 152 throw new BaseException(ex); 153 } 154 } 155 156 List l=SharkUtilities.createAssignmentWrappers(t,userAuth,username); 157 if (max_number > l.size() || max_number<=0) { 158 max_number = l.size(); 159 } 160 WfAssignment[] ret = new WfAssignment[l.size()]; 161 l.subList(0, max_number).toArray(ret); 162 return ret; 163 164 } 165 166 170 public boolean is_member_of_work_items(WfAssignment member) throws BaseException { 171 boolean ret = false; 172 SharkTransaction t = null; 173 try { 174 t = SharkUtilities.createTransaction(); 175 ret = is_member_of_work_items(t, member); 176 } catch (RootException e) { 178 SharkUtilities.emptyCaches(t); 180 if (e instanceof BaseException) 181 throw (BaseException)e; 182 else 183 throw new BaseException(e); 184 } finally { 185 SharkUtilities.releaseTransaction(t); 186 } 187 return ret; 188 } 189 190 public boolean is_member_of_work_items(SharkTransaction t,WfAssignment member) throws BaseException { 191 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 192 if (sm!=null) { 193 try { 194 sm.check_resource_is_member_of_work_items(t, 195 username, 196 userAuth); 197 } catch (Exception ex) { 198 throw new BaseException(ex); 199 } 200 } 201 202 String resUn=member.assignee(t).resource_key(t); 203 return resUn.equals(username); 204 } 205 206 209 public String resource_key () throws BaseException { 210 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 211 if (sm==null) { 212 return username; 213 } 214 String ret = null; 215 SharkTransaction t = null; 216 try { 217 t = SharkUtilities.createTransaction(); 218 ret = resource_key(t); 219 } catch (RootException e) { 221 SharkUtilities.emptyCaches(t); 223 if (e instanceof BaseException) 224 throw (BaseException)e; 225 else 226 throw new BaseException(e); 227 } finally { 228 SharkUtilities.releaseTransaction(t); 229 } 230 return ret; 231 } 232 233 public String resource_key (SharkTransaction t) throws BaseException { 234 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 235 if (sm!=null) { 236 try { 237 sm.check_resource_resource_key(t, 238 username, 239 userAuth); 240 } catch (Exception ex) { 241 throw new BaseException(ex); 242 } 243 } 244 245 return username; 246 } 247 248 251 public String resource_name () throws BaseException { 252 String ret = null; 253 SharkTransaction t = null; 254 try { 255 t = SharkUtilities.createTransaction(); 256 ret = resource_name(t); 257 } catch (RootException e) { 259 SharkUtilities.emptyCaches(t); 261 if (e instanceof BaseException) 262 throw (BaseException)e; 263 else 264 throw new BaseException(e); 265 } finally { 266 SharkUtilities.releaseTransaction(t); 267 } 268 return ret; 269 } 270 271 public String resource_name (SharkTransaction t) throws BaseException { 272 WfResourceInternal resInternal=WfResourceWrapper.getResourceImpl(t,username); 273 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 274 if (sm!=null) { 275 try { 276 sm.check_resource_resource_name(t, 277 username, 278 userAuth); 279 } catch (Exception ex) { 280 throw new BaseException(ex); 281 } 282 } 283 284 return resInternal.resource_name(t); 285 } 286 287 290 public void release (WfAssignment from_assigment, String release_info) throws BaseException, NotAssigned { 291 SharkTransaction t = null; 292 try { 293 t = SharkUtilities.createTransaction(); 294 release(t,from_assigment,release_info); 295 SharkUtilities.commitTransaction(t); 296 } catch (RootException e) { 297 SharkUtilities.rollbackTransaction(t,e); 298 SharkUtilities.emptyCaches(t); 299 if (e instanceof BaseException) 300 throw (BaseException)e; 301 else 302 throw new BaseException(e); 303 } finally { 304 SharkUtilities.releaseTransaction(t); 305 } 306 } 307 308 public void release (SharkTransaction t,WfAssignment from_assigment, String release_info) throws BaseException, NotAssigned { 309 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 310 if (sm!=null) { 311 try { 312 sm.check_resource_release(t, 313 username, 314 userAuth); 315 } catch (Exception ex) { 316 throw new BaseException(ex); 317 } 318 } 319 } 320 321 public String toString () { 322 return "[Id="+username+"]"; 323 } 324 325 329 public boolean equals (Object obj) { 330 if (!(obj instanceof WfResource)) return false; 331 WfResource res=(WfResource)obj; 332 try { 333 if (obj instanceof WfResourceWrapper) { 334 return ((WfResourceWrapper)obj).username.equals(username); 335 } else { 336 return res.resource_key().equals(username); 337 } 338 } catch (Exception ex) { 339 return false; 340 } 341 } 342 343 private static WfResourceInternal getResourceImpl ( 344 SharkTransaction t, 345 String username) throws BaseException { 346 WfResourceInternal res=SharkUtilities.getResource(t,username); 347 if (res==null) throw new BaseException("Resource does not exist"); 348 return res; 349 } 350 } 351 | Popular Tags |