1 package org.enhydra.shark; 2 3 import java.util.ArrayList ; 4 import java.util.HashMap ; 5 import java.util.List ; 6 import java.util.Map ; 7 import org.enhydra.shark.api.RootException; 8 import org.enhydra.shark.api.SharkTransaction; 9 import org.enhydra.shark.api.client.wfbase.BaseException; 10 import org.enhydra.shark.api.client.wfmodel.WfResource; 11 import org.enhydra.shark.api.client.wfservice.WfResourceIterator; 12 import org.enhydra.shark.api.common.SharkConstants; 13 import org.enhydra.shark.api.internal.instancepersistence.ResourcePersistenceInterface; 14 import org.enhydra.shark.api.internal.scripting.Evaluator; 15 16 17 23 public class WfResourceIteratorWrapper extends BaseIteratorWrapper implements WfResourceIterator { 24 25 protected WfResourceIteratorWrapper (SharkTransaction t,String userAuth) throws BaseException { 26 super(userAuth); 27 } 28 29 public WfResource get_next_object () throws BaseException { 30 WfResource ret=null; 31 SharkTransaction t = null; 32 try { 33 t = SharkUtilities.createTransaction(); 34 ret = get_next_object(t); 35 } catch (RootException e) { 37 SharkUtilities.emptyCaches(t); 39 if (e instanceof BaseException) 40 throw (BaseException)e; 41 else 42 throw new BaseException(e); 43 } finally { 44 SharkUtilities.releaseTransaction(t); 45 } 46 return ret; 47 } 48 49 public WfResource get_next_object (SharkTransaction t) throws BaseException { 50 return (WfResource)super.getNextObject(t); 51 } 52 53 public WfResource get_previous_object () throws BaseException { 54 WfResource ret=null; 55 SharkTransaction t = null; 56 try { 57 t = SharkUtilities.createTransaction(); 58 ret = get_previous_object(t); 59 } catch (RootException e) { 61 SharkUtilities.emptyCaches(t); 63 if (e instanceof BaseException) 64 throw (BaseException)e; 65 else 66 throw new BaseException(e); 67 } finally { 68 SharkUtilities.releaseTransaction(t); 69 } 70 return ret; 71 } 72 73 public WfResource get_previous_object (SharkTransaction t) throws BaseException { 74 return (WfResource)super.getPreviousObject(t); 75 } 76 77 public WfResource[] get_next_n_sequence (int max_number) throws BaseException { 78 WfResource[] ret=null; 79 SharkTransaction t = null; 80 try { 81 t = SharkUtilities.createTransaction(); 82 ret = get_next_n_sequence(t,max_number); 83 } catch (RootException e) { 85 SharkUtilities.emptyCaches(t); 87 if (e instanceof BaseException) 88 throw (BaseException)e; 89 else 90 throw new BaseException(e); 91 } finally { 92 SharkUtilities.releaseTransaction(t); 93 } 94 return ret; 95 } 96 97 public WfResource[] get_next_n_sequence (SharkTransaction t,int max_number) throws BaseException { 98 List l=super.getNextNSequence(t,max_number); 99 WfResource[] ret=new WfResource[l.size()]; 100 l.toArray(ret); 101 return ret; 102 } 103 104 public WfResource[] get_previous_n_sequence (int max_number) throws BaseException { 105 WfResource[] ret=null; 106 SharkTransaction t = null; 107 try { 108 t = SharkUtilities.createTransaction(); 109 ret = get_previous_n_sequence(t,max_number); 110 } catch (RootException e) { 112 SharkUtilities.emptyCaches(t); 114 if (e instanceof BaseException) 115 throw (BaseException)e; 116 else 117 throw new BaseException(e); 118 } finally { 119 SharkUtilities.releaseTransaction(t); 120 } 121 return ret; 122 } 123 124 public WfResource[] get_previous_n_sequence (SharkTransaction t,int max_number) throws BaseException { 125 List l=super.getPreviousNSequence(t,max_number); 126 WfResource[] ret=new WfResource[l.size()]; 127 l.toArray(ret); 128 return ret; 129 } 130 131 protected void fillObjectList (SharkTransaction t) throws BaseException { 132 if (objectList!=null) return; 133 try { 134 List resources = new ArrayList (); 135 List l = SharkEngineManager.getInstance() 136 .getInstancePersistenceManager() 137 .getResourcesWhere(t, sqlWhere); 138 Evaluator evaluator = SharkEngineManager.getInstance() 139 .getScriptingManager() 140 .getEvaluator(t, queryGrammar); 141 for (int i = 0; i < l.size(); i++) { 142 ResourcePersistenceInterface po=(ResourcePersistenceInterface)l.get(i); 143 boolean toAdd=true; 144 if (eval) { 145 Map context=new HashMap (); 146 context.put(SharkConstants.RES_USERNAME,po.getUsername()); 147 if (queryExpression.indexOf(SharkConstants.RES_NO_OF_ASSIGNMENTS)!=-1) { 148 Long lng=new Long (SharkEngineManager 149 .getInstance() 150 .getInstancePersistenceManager() 151 .getAllValidAssignmentsForResource(po.getUsername(),t).size()); 152 context.put(SharkConstants.RES_NO_OF_ASSIGNMENTS,lng); 153 } 154 toAdd=evaluator.evaluateCondition(t,queryExpression,context); 155 } 156 if (toAdd) { 157 resources.add(SharkEngineManager.getInstance() 158 .getObjectFactory() 159 .createResourceWrapper(userAuth, po.getUsername())); 160 } 161 } 162 setObjectList(resources); 163 } catch (Exception ex) { 164 throw new BaseException(ex); 165 } 166 } 167 } 168 | Popular Tags |