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 zeus.actors.*;
26  import FIPA.*; 
27  
28  /*** 
29      Class that provides a MTS that implements the FIPA 2000 spec (XC00075)
30      @author Simon Thompson
31      @since 1.1
32      */
33  public class FIPA_2000_IIOP_Transport implements OutTray { 
34      
35      /*** 
36          mts used to internally implement transport functionality
37          */
38      private FIPA.MTS mts = null; 
39  
40      
41      
42      /*** 
43          this transport must be implemented with a valid FIPA.MTS object. <p> 
44          The FIPA.MTS in question should have been generated by calling a 
45          CORBA orb and retreiving a reference to a FIPA.MTS that had been 
46          bound there by a third party. <p> 
47          The recommeneded way of doing this is to use zeus.actors.service.TransportMethod to 
48          generate a TransportFactory (probably the IIOP_Z_TransportFactory, but 
49          possibly another one depending on what version of zeus or other related 
50          product you are using). Once you have the TransportFactory reference you must 
51          then call getTransport which will return an instance of this class. 
52          <p> Alternatively, you must venture into the realms of corba coding and 
53          sort this out yourself!
54          <p> 
55          @see zeus.actors.service.TransportMethod*/
56      public FIPA_2000_IIOP_Transport (FIPA.MTS mts) { 
57          this.mts = mts; 
58      }
59      
60     
61      public void send  (Object obj) throws UnsuitableMessageException { 
62          try { 
63              javax.agent.Envelope env = (javax.agent.Envelope) obj; 
64              send (env); 
65          } catch (ClassCastException cce) { 
66              throw new UnsuitableMessageException ("Must be javax.agent.envelope to work with this transport"); 
67          }catch (Exception e) { 
68              e.printStackTrace(); 
69              throw new UnsuitableMessageException ("Bad message in send() - unknown problem, Excepiton printed to sout"); 
70           
71          }
72       }
73       
74      
75      public void send (javax.agent.Envelope envelope) { 
76          Identifier sender = envelope.getSender(); 
77          Identifier receiver = envelope.getReceiver(); 
78          Object payload = envelope.getObject();
79          try { 
80              zeus.concepts.FIPAPerformative fperf = (zeus.concepts.FIPAPerformative) payload;       
81              debug ("Performative is : \n" + fperf.toFIPAString()); 
82              FIPA.Envelope fenv = new FIPA.Envelope(); 
83             
84              try { 
85              fenv.to = fperf.getReceiversAgentID(); 
86  
87                     } catch (NullPointerException npe) { ;}
88              try { 
89              fenv.from = fperf.getSenderAgentID(); 
90                     } catch (NullPointerException npe) { 
91                      fenv.from = new FIPA.AgentID[0];}
92                      //("null",new String[0], new FIPA.AgentID[0], new FIPA.Property[0]);}
93              try { 
94              fenv.comments = new String ("Zeus Agent Building Environment v1.1"); 
95                     } catch (NullPointerException npe) { ;}
96  
97              fenv.payloadLength = -1; // indicates that it is up to the ACC to work this out. 
98  
99              fenv.payloadEncoding = new String ("String"); 
100 
101             fenv.aclRepresentation = new String ("fipa.acl.rep.string.std"); 
102 
103             fenv.date = new FIPA.DateTime[0];
104    
105             fenv.encrypted = new String [1]; 
106 
107             fenv.encrypted[0] = fperf.getEncryptionScheme(); 
108 
109             fenv.intendedReceiver = fperf.getReceiversAgentID (); 
110       
111           //  fenv.intendedReceiver[0].getAddress
112       
113             fenv.received = new FIPA.ReceivedObject[0];
114 
115             fenv.transportBehaviour = new FIPA.Property[0][0];
116 
117             fenv.userDefinedProperties = new FIPA.Property[0]; 
118 
119             FIPA.Envelope envelopes[]  = {fenv}; 
120             
121             FIPA.FipaMessage message = new FIPA.FipaMessage(envelopes,fperf.toFIPAString().getBytes());
122             debug ("Sending message "+message.toString()); 
123             mts.message (message); 
124             debug ("message sent"); 
125             
126             
127          }        
128          catch (ClassCastException cce) {            
129                     // I know that this is a bit grim.... 
130                     // let's not bring everything down for one mistake...
131                     cce.printStackTrace(); 
132                     return; 
133                 } 
134     }
135     
136     
137    
138     private void debug (String str) { 
139             System.out.println("FIPA_2000_IIOP_Transport >>" + str); 
140     }
141     
142 }