1 2 3 package org.enhydra.shark.asap; 4 5 import java.io.*; 6 import java.io.FileOutputStream ; 7 import java.io.ObjectOutputStream ; 8 import java.util.*; 9 10 import org.apache.axis.types.URI; 11 import org.enhydra.shark.api.SharkTransaction; 12 import org.enhydra.shark.api.client.wfbase.BaseException; 13 import org.enhydra.shark.api.client.wfmodel.*; 14 15 18 public class RequesterImpl implements WfRequester { 19 20 private static String FILELOC = "/tmp/t.tmp"; 21 static Map obs; 22 23 static URI add; 24 25 static { 26 try { 27 FILELOC = System.getProperty("user.home")+File.separatorChar+".wfxmlsharkobservers"; 28 FileInputStream istream = new FileInputStream(FILELOC); 29 ObjectInputStream p = new ObjectInputStream(istream); 30 31 add = (URI) p.readObject(); 32 obs = (Map) p.readObject(); 33 34 istream.close(); 35 } catch (Throwable _) { 36 obs = new HashMap(); 37 add = null; 38 _.printStackTrace(); 39 } 40 } 41 42 public RequesterImpl() {} 43 44 public void addObserver(URI instance, URI observer) { 45 if (null == add) add = instance; 47 getObservers(instance).add(observer); 48 try { 49 FileOutputStream ostream = new FileOutputStream (FILELOC); 50 ObjectOutputStream p = new ObjectOutputStream (ostream); 51 52 p.writeObject(add); 53 p.writeObject(obs); 54 55 p.flush(); 56 ostream.close(); 57 } catch (Throwable _) { 58 _.printStackTrace(); 59 } 60 } 61 62 public void removeObserver(URI instance, URI observer) { 63 getObservers(instance).remove(observer); 64 } 65 66 public Set getObservers(URI instance) { 67 Set observers = (Set) obs.get(instance); 68 if (null == observers) { 69 observers = new HashSet(); 70 obs.put(instance, observers); 71 } 72 return observers; 73 } 74 75 public int how_many_performer() throws BaseException { 76 return 0; 78 } 79 80 public int how_many_performer(SharkTransaction t) throws BaseException { 81 return 0; 83 } 84 85 public WfProcessIterator get_iterator_performer() throws BaseException { 86 return null; 88 } 89 90 public WfProcessIterator get_iterator_performer(SharkTransaction t) throws BaseException { 91 return null; 93 } 94 95 public WfProcess[] get_sequence_performer(int max_number) throws BaseException { 96 return null; 98 } 99 100 public WfProcess[] get_sequence_performer(SharkTransaction t, 101 int max_number) throws BaseException { 102 return null; 104 } 105 106 public boolean is_member_of_performer(WfProcess member) throws BaseException { 107 return false; 109 } 110 111 public boolean is_member_of_performer(SharkTransaction t, WfProcess member) throws BaseException { 112 return false; 114 } 115 116 public void receive_event(final WfEventAudit event) throws BaseException, 117 InvalidPerformer { 118 throw new BaseException("Not implemented"); 119 } 120 121 public void receive_event(SharkTransaction t, WfEventAudit event) throws BaseException, 122 InvalidPerformer { 123 124 System.out.println("Web Service Requester received an event."); 125 126 if (!(event instanceof WfStateEventAudit)) return; 127 128 WfProcess proc = null; 129 try { 130 proc = (WfProcess) event.source(t); 131 String procId = event.process_key(); 132 String new_state = ((WfStateEventAudit) event).new_state(); 133 String old_state = ((WfStateEventAudit) event).old_state(); 134 Map result = proc.result(t); 135 System.out.println("Notifying observers for process " 136 + procId + " ..."); 137 URI myAddress = new URI(add); 138 myAddress.setQueryString(SharkServiceImpl.QSPN_PROCESS_INSTANCE 139 + ((WfStateEventAudit) event).process_key()); 140 AsapBindingUtilitiesImpl.notifyObservers(procId, 141 myAddress.toString(), 142 result, 143 new_state, 144 old_state, 145 getObservers(myAddress)); 146 } catch (Exception ex) { 147 throw new BaseException(ex); 148 } 149 } 150 } 151 152 | Popular Tags |