KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > asap > RequesterImpl


1 /* RequesterImpl.java */
2
3 package org.enhydra.shark.asap;
4
5 import java.io.*;
6 import java.io.FileOutputStream JavaDoc;
7 import java.io.ObjectOutputStream JavaDoc;
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 /**
16  * @author V.Puskas, S.Bojanic
17  */

18 public class RequesterImpl implements WfRequester {
19
20    private static String JavaDoc 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 JavaDoc _) {
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       //System.out.println("Adding observer " + observer);
46
if (null == add) add = instance;
47       getObservers(instance).add(observer);
48       try {
49          FileOutputStream JavaDoc ostream = new FileOutputStream JavaDoc(FILELOC);
50          ObjectOutputStream JavaDoc p = new ObjectOutputStream JavaDoc(ostream);
51          
52          p.writeObject(add);
53          p.writeObject(obs);
54          
55          p.flush();
56          ostream.close();
57       } catch (Throwable JavaDoc _) {
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       // TODO Auto-generated method stub
77
return 0;
78    }
79
80    public int how_many_performer(SharkTransaction t) throws BaseException {
81       // TODO Auto-generated method stub
82
return 0;
83    }
84
85    public WfProcessIterator get_iterator_performer() throws BaseException {
86       // TODO Auto-generated method stub
87
return null;
88    }
89
90    public WfProcessIterator get_iterator_performer(SharkTransaction t) throws BaseException {
91       // TODO Auto-generated method stub
92
return null;
93    }
94
95    public WfProcess[] get_sequence_performer(int max_number) throws BaseException {
96       // TODO Auto-generated method stub
97
return null;
98    }
99
100    public WfProcess[] get_sequence_performer(SharkTransaction t,
101                                              int max_number) throws BaseException {
102       // TODO Auto-generated method stub
103
return null;
104    }
105
106    public boolean is_member_of_performer(WfProcess member) throws BaseException {
107       // TODO Auto-generated method stub
108
return false;
109    }
110
111    public boolean is_member_of_performer(SharkTransaction t, WfProcess member) throws BaseException {
112       // TODO Auto-generated method stub
113
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 JavaDoc procId = event.process_key();
132          String JavaDoc new_state = ((WfStateEventAudit) event).new_state();
133          String JavaDoc 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 JavaDoc ex) {
147          throw new BaseException(ex);
148       }
149    }
150 }
151
152
Popular Tags