View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-2001. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  package zeus.actors.outtrays;
22  
23  import javax.agent.service.*; 
24  import javax.agent.*; 
25  import FIPA.*; 
26  import fipa97.FIPA_Agent_97;
27  import zeus.concepts.*;
28  import zeus.actors.*;
29  
30  /*** 
31      implementation of the OutTray interface that wraps a FIPA_97_IIOP transport 
32      ie. a FIPA_Agent_97 interface 
33      */
34  public class FIPA_97_IIOP_Transport implements OutTray { 
35          
36          
37      private FIPA_Agent_97 target = null; 
38      
39      
40      public FIPA_97_IIOP_Transport (FIPA_Agent_97 target) { 
41          this.target = target; 
42      }
43      
44      
45      public void send  (Object obj) throws UnsuitableMessageException { 
46      try { 
47          javax.agent.Envelope env = (javax.agent.Envelope) obj; 
48          send (env); 
49          } catch (ClassCastException cce) { 
50              throw new UnsuitableMessageException ("Must be javax.agent.envelope to work with this transport"); 
51          }catch (Exception e) { 
52              e.printStackTrace(); 
53              throw new UnsuitableMessageException ("Bad message in send() - unknown problem, Excepiton printed to sout"); 
54       
55      }
56      }
57      
58      /*** 
59          send takes the Envelope, pops out the "object" and then tries 
60          to cast it to a zeus.concepts.FIPAPerformative. If it can't do that 
61          it will fail, and print a stack trace. If it can cast it, it will call 
62          the FIPA_Agent_97.message(FIPAPerformative.toString()) and send it 
63          down the wire
64          */
65      public void send (javax.agent.Envelope envelope) { 
66          // must convert the javax.agent.Envelope to a FIPAPerformative, toString it and 
67          // send it 
68          try {
69              FIPAPerformative fperf = (FIPAPerformative) envelope.getObject (); 
70              target.message(fperf.toFIPAString()); 
71          }
72          catch (ClassCastException cce) { 
73                      // I know that this is a bit grim.... 
74                      // let's not bring everything down for one mistake...
75                      cce.printStackTrace(); 
76                      return; 
77                  } 
78              
79          
80      }
81     
82  
83  }