KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corba > poa > SharkConnectionCORBA


1 package org.enhydra.shark.corba.poa;
2
3 import org.enhydra.shark.corba.WorkflowService.*;
4 import org.enhydra.shark.corba.poa.Collective;
5 import org.omg.CORBA.ORB JavaDoc;
6 import org.omg.WfBase.BaseException;
7 import org.omg.WorkflowModel.*;
8 import org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc;
9 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc;
10 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
11
12 /**
13  * The client interface through which client accesses the engine
14  * objects, and performs the various actions on engine.
15  *
16  * @author David Forslund
17  * @version 0.2
18  */

19 public class SharkConnectionCORBA extends SharkConnectionPOA implements Collective {
20
21    org.enhydra.shark.api.client.wfservice.SharkConnection mySharkConn;
22    private SharkCORBAServer myServer;
23
24    SharkConnectionCORBA(SharkCORBAServer server, org.enhydra.shark.api.client.wfservice.SharkConnection sc) {
25       this.myServer = server;
26       this.mySharkConn = sc;
27
28       /*
29        try {
30            myServer._default_POA().activate_object(this) ;
31
32        } catch (WrongPolicy wrongPolicy) {
33            wrongPolicy.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
34        } catch (ServantAlreadyActive servantAlreadyActive) {
35            servantAlreadyActive.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
36        }
37
38        _this(myServer._orb());
39        */

40       if (myServer.trackObjects) {
41          __collective = new Collective.CollectiveCORBA();
42       }
43    }
44
45    public void connect(String JavaDoc userId,
46                        String JavaDoc password,
47                        String JavaDoc engineName,
48                        String JavaDoc scope) throws BaseException, ConnectFailed {
49       try {
50          mySharkConn.connect(userId, password, engineName, scope);
51       } catch (org.enhydra.shark.api.client.wfservice.ConnectFailed cf) {
52          throw new ConnectFailed();
53       } catch (Exception JavaDoc ex) {
54          throw new BaseException();
55       }
56    }
57
58    public void disconnect() throws BaseException, NotConnected {
59       try {
60          mySharkConn.disconnect();
61       } catch (org.enhydra.shark.api.client.wfservice.NotConnected nc) {
62          throw new NotConnected(nc.getMessage());
63       } catch (Exception JavaDoc ex) {
64          throw new BaseException();
65       } finally {
66          this.__disband(this._orb());
67       }
68    }
69
70    public WfResource getResourceObject() throws BaseException, NotConnected {
71       try {
72          WfResource wfRes = SharkCORBAUtilities.makeWfResource( new WfResourceCORBA(myServer.getBoundORB(), this,
73                                     mySharkConn.getResourceObject()));
74          __recruit(wfRes);
75           return wfRes;
76       } catch (org.enhydra.shark.api.client.wfservice.NotConnected nc) {
77          throw new NotConnected(nc.getMessage());
78       } catch (Exception JavaDoc ex) {
79          throw new BaseException();
80       }
81    }
82
83    public WfProcess createProcess(String JavaDoc pkgId, String JavaDoc pDefId) throws BaseException,
84                                                               NotConnected,
85                                                               NotEnabled {
86       try {
87          WfProcess proc = SharkCORBAUtilities.makeWfProcess(new WfProcessCORBA(myServer.getBoundORB(),this,
88                                                  mySharkConn.createProcess(pkgId,
89                                                                            pDefId)));
90           __recruit(proc);
91           return proc;
92
93       } catch (org.enhydra.shark.api.client.wfservice.NotConnected nc) {
94          throw new NotConnected(nc.getMessage());
95       } catch (org.enhydra.shark.api.client.wfmodel.NotEnabled ne) {
96          throw new NotEnabled(ne.getMessage());
97       } catch (Exception JavaDoc ex) {
98          throw new BaseException();
99       }
100    }
101
102    public WfProcess createProcessWithRequester (WfRequester requester,
103          String JavaDoc pkgId,
104          String JavaDoc pDefId) throws BaseException,
105                                NotConnected,
106                                NotEnabled,
107                                InvalidRequester,
108                                RequesterRequired {
109       try {
110          WfLinkingRequesterForCORBA lr = new WfLinkingRequesterForCORBA();
111           lr.setOrb(myServer._orb());
112          org.enhydra.shark.api.client.wfmodel.WfProcess procInternal=
113             mySharkConn.createProcess(lr,pkgId,pDefId);
114          WfLinkingRequesterForCORBA.setCORBARequester(procInternal.key(), requester);
115          WfProcess proc = SharkCORBAUtilities.makeWfProcess(new WfProcessCORBA(myServer.getBoundORB(), this,procInternal));
116          __recruit(proc);
117           return proc;
118       } catch (org.enhydra.shark.api.client.wfservice.NotConnected nc) {
119          throw new NotConnected(nc.getMessage());
120       } catch (org.enhydra.shark.api.client.wfmodel.NotEnabled ne) {
121          throw new NotEnabled(ne.getMessage());
122       } catch (org.enhydra.shark.api.client.wfmodel.InvalidRequester ir) {
123          throw new InvalidRequester(ir.getMessage());
124       } catch (org.enhydra.shark.api.client.wfmodel.RequesterRequired rr) {
125          throw new RequesterRequired(rr.getMessage());
126       } catch (Exception JavaDoc ex) {
127          throw new BaseException();
128       }
129
130    }
131    Collective __collective;
132
133    public void __recruit(org.omg.CORBA.Object JavaDoc obj) {
134       if (myServer.trackObjects)
135          __collective.__recruit(obj);
136    }
137
138    public void __leave(org.omg.CORBA.Object JavaDoc obj) {
139       if (myServer.trackObjects)
140          __collective.__leave(obj);
141    }
142
143    public void __disband(ORB JavaDoc _orb) {
144       if (myServer.trackObjects) {
145          __collective.__disband(_orb);
146        _this()._release();
147        /*
148        try {
149            this.disconnect();
150        } catch (BaseException e) {
151            e.printStackTrace();
152        } catch (NotConnected notConnected) {
153            notConnected.printStackTrace();
154        } */

155        }
156    }
157
158    public void doneWith(org.omg.CORBA.Object JavaDoc toDisconnect) {
159       myServer.doneWith(toDisconnect);
160       __leave(toDisconnect);
161    }
162 }
Popular Tags