IBM Agent Building Environment Developer's Toolkit


Appendix A. Reminder Agent Sample Formatted Code

Client Code for Reminder Sample Application


RemClient Class

 
    1   /*************************************************************************
    2   ** File:         RemClient.java
    3   ** Description:  Client Driver for Sample Reminder Agent
    4   **
    5   ** DISCLAIMER OF WARRANTIES:
    6   ** -------------------------
    7   ** The following [enclosed] code is sample code created by IBM
    8   ** Corporation.  This sample code is not part of any standard IBM product
    9   ** and is provided to you solely for the purpose of assisting you in the
   10   ** development of your applications.  The code is provided "AS IS",
   11   ** without warranty of any kind.  IBM shall not be liable for any damages
   12   ** arising out of your use of the sample code, even if they have been
   13   ** advised of the possibility of such damages.
   14   *************************************************************************/
   15
   16   /* RemClient.java
   17    * This class provides a command line input to the RemAgent socket interface
   18   */
   19
   20   import java.net.*;
   21   import java.io.*;
   22   import java.util.*;
   23
   24  *public class RemClient {
   25  |   public static boolean debug = true;
   26  |   private static String IPAddr;
   27  |
   28  |  *public static void main(String args[]) {
   29  |  |   BufferedReader  cmdin = new BufferedReader(new InputStreamReader(System.in));
   30  |  |   String command = null;
   31  |  |
   32  |  |   if (args.length == 1)
   33  |  |      IPAddr = args[0];  //set IP address from input argument
   34  |  |  *else {
   35  |  |  |   System.out.println("Exception: IP address required as input argument");
   36  |  |  |   System.exit(1);
   37  |  |  *  }
   38  |  |
   39  |  |*try {
   40  |  ||  System.out.println(" Enter command to send to server (QUIT to leave, ? for list of cmds): ");
   41  |  || *while ((command = cmdin.readLine()) != null) {
   42  |  || |   StringTokenizer st = new StringTokenizer(command, " ");
   43  |  || |   String cmd = st.nextToken().toUpperCase();
   44  |  || |   if (cmd.equals("QUIT")) break;
   45  |  || |   else if (cmd.equals("?")) help();
   46  |  || |   else send(command);
   47  |  || *   }
   48  |  |*  }
   49  |  |  *catch (Exception e) {
   50  |  |  |   fail(e, "IOException sending data to server");
   51  |  |  *}
   52  |  *}
   53  |
   54  |  *public static void fail(Exception e, String msg) {
   55  |  |   System.err.println(msg + ": " + e);
   56  |  |   System.exit(1);
   57  |  *}
   58  |
   59  |  *public static void send(String socketData) {
   60  |  | Socket client_socket;
   61  |  | PrintWriter out;
   62  |  |
   63  |  |*try {
   64  |  ||   client_socket = new Socket(IPAddr, 6789);  // Connect, providing IP addr and port
   65  |  ||
   66  |  ||   out = new PrintWriter(client_socket.getOutputStream(), true); // Get output stream
   67  |  ||   if (debug)  System.out.println("About to write data to socket:" + socketData );
   68  |  ||   out.println(socketData);                                // Write data
   69  |  ||   receive(client_socket);                                 // invoke recieve to get response
   70  |  ||   out.close();                                            // Close DataOutputStream
   71  |  ||   if (debug)  System.out.println("Closed DataOutputStream");
   72  |  |*  }
   73  |  | *catch (Exception e) {
   74  |  | |    fail(e, "Exception sending data to server");
   75  |  | * }
   76  |  |if (debug)  System.out.println("Exiting Send routine");
   77  |  *}
   78  |
   79  |  *public static void receive(Socket client_socket) {
   80  |  |  BufferedReader in;
   81  |  |  String line;
   82  |  |
   83  |  | *try {
   84  |  | |  in = new BufferedReader(new InputStreamReader(client_socket.getInputStream())); // Get input stream
   85  |  | |  if (debug)  System.out.println("About to receive data from socket");
   86  |  | | *while ((line = in.readLine()) != null) {                  // receive on input stream
   87  |  | | |   System.out.println("Received following response: " + line);// print what was received
   88  |  | | *}
   89  |  | |  if (debug)  System.out.println("End of receiving responses from server");
   90  |  | |  in.close();                                               // close input stream
   91  |  | |  if (debug)  System.out.println("Closed BufferedReader");
   92  |  | *}
   93  |  |   *catch (Exception e) {
   94  |  |   | fail(e, "Exception receiving response data from server");
   95  |  |   *}
   96  |  *}
   97  |
   98  |  *public static void help() {
   99  |  |   System.out.println("\tQUIT - to terminate the client program");
  100  |  |   System.out.println("\tGet:UserID - to retrieve all reminders for user");
  101  |  |   System.out.println("\tPut:UserID:RemString            - to save reminders ");
  102  |  |   System.out.println("\t   where RemString is of the format: ID$000$tokenStr (ID is a keyword)");
  103  |  |   System.out.println("\t   and   tokenStr is of the format: key=value#key=value#...");
  104  |  |   System.out.println("\t         (key is for documentation, data is positional as follows:)");
  105  |  |   System.out.println("\t         typeOfEvent=Birthday#nameOfEvent=My Birthday#month=March");
  106  |  |   System.out.println("\t         #day=10#year=1997#count=5#via=E-Mail#user=Janet");
  107  |  |   System.out.println("\t           (- when anything other than E-Mail is used, you must explicitly go)");
  108  |  |   System.out.println("\t           (-   to the reminder server to retrieve reminder messages.)");
  109  |  |   System.out.println("\t         #emailAddr=user@address.com");
  110  |  |   System.out.println("\t         (count is number of days BEFORE event date (when notifications should begin))");
  111  |  |   System.out.println("\tRemove:UserID:RemID             - to remove a reminder");
  112  |  |   System.out.println("\tModify:UserID:RemString            - to replace a reminder ");
  113  |  |   System.out.println("\t   where RemString is of the format: ID$nnn$tokenStr (ID is a keyword)");
  114  |  |   System.out.println("\t         (- ID is a keyword)");
  115  |  |   System.out.println("\t         (- substitute reminder id for nnn above)");
  116  |  |   System.out.println("\t         (  - reminder id is returned by a Put command)");
  117  |  |   System.out.println("\t   and   tokenStr is of the format  key=value#key=value#...");
  118  |  |   System.out.println("\t         (key is ignored, data is presently positional as follows:)");
  119  |  |   System.out.println("\t         typeOfEvent=Birthday#nameOfEvent=My Birthday#month=March");
  120  |  |   System.out.println("\t         #day=10#year=1997#count=5#via=E-Mail#user=Janet");
  121  |  |   System.out.println("\t         #emailAddr=user@address.com");
  122  |  |   System.out.println("\t         (count is number of days BEFORE event date that notify should occur)");
  123  |  |   System.out.println("\tGetMsgs:UserID                  - to get all messages for user and mark them as read");
  124  |  |   System.out.println("\tGetMsgsNoMark:UserID            - to get all message for user but NOT mark them as read");
  125  |  |   System.out.println("\tDelMsgs:UserID:MsgID,MsgID,...  - to delete specified messages for user");
  126  |  |   System.out.println("\tMarkMsgsAsNew:UserID:MsgID,...  - to mark all user's messages as unread");
  127  |  |   System.out.println("\tStatusMsgs:UserID               - to query if any new messages exist for user");
  128  |  *   }
  129  |
  130  *}

Server Code for Reminder Sample Application


RemAgent Class

 
    1   /*************************************************************************
    2   ** File:         RemAgent.java
    3   ** Description:  Sample Agent for Reminders
    4   **
    5   ** DISCLAIMER OF WARRANTIES:
    6   ** -------------------------
    7   ** The following [enclosed] code is sample code created by IBM
    8   ** Corporation.  This sample code is not part of any standard IBM product
    9   ** and is provided to you solely for the purpose of assisting you in the
   10   ** development of your applications.  The code is provided "AS IS",
   11   ** without warranty of any kind.  IBM shall not be liable for any damages
   12   ** arising out of your use of the sample code, even if they have been
   13   ** advised of the possibility of such damages.
   14   *************************************************************************/
   15
   16   /* RemAgent.java
   17    * This class provides reminders to clients in the form of EMAIL or direct
   18    * message generation.  Clients are able to
   19    * set or edit reminders and receive and manipulate messages.
   20    */
   21
   22   import ibm.AgentBuilder.aeapi.IAAgent;
   23   import ibm.AgentBuilder.aeapi.IAAdapterHandle;
   24   import ibm.AgentBuilder.aeapi.IAEngineHandle;
   25   import ibm.AgentBuilder.aeapi.IALibraryHandle;
   26   import ibm.AgentBuilder.misc.IAError;
   27   import ibm.AgentBuilder.Adapter.IAAdapter;
   28   import ibm.AgentBuilder.Library.*;
   29   import ibm.AgentBuilder.misc.*;
   30   import java.net.*;
   31   import java.io.*;
   32   import java.util.*;
   33
   34  *public class RemAgent extends IAAgent {
   35  |
   36  |   static RemAgent theAgent;            //IAAgent implementation..
   37  |   Server server;
   38  |   public static IAEngineHandle  engineHandle;
   39  |   public static IALibraryHandle libHandle;
   40  |   private IALibrary appLibrary;
   41  |   private IALibInferenceCollector appTopCollector;
   42  |   private String cfgFileName;
   43  |   static String ruleSetMetadataString =
   44  |          "BEGIN PREDICATES" + "\n" +
   45  |             "EventName(string);" + "\n" +
   46  |             "AlarmId(string);" + "\n" +
   47  |             "EventTime(string,string);" + "\n" +
   48  |             "addTimeInterval(string, string, Integer, string, string, string);" + "\n" +
   49  |             "currentTimeBetween(string,string,string,string);" + "\n" +
   50  |             "setRandomStartBoundedIntervalAlarm" +
   51  |                    "(integer,string,string,string,integer,string,string);" + "\n" +
   52  |             "setEndBoundedIntervalAlarm" +
   53  |                    "(integer,string,string,string,string,string);" + "\n" +
   54  |             "setRandomBoundedIntervalAlarm" +
   55  |                    "(integer,string,string,string,string,string,integer,string,string);" + "\n" +
   56  |             "EMailWithSubject(string, string,string);" + "\n" +
   57  |             "SetMessage(string);" + "\n" +
   58  |          "END PREDICATES" + "\n" +
   59  |          "BEGIN SENSORS" + "\n" +
   60  |             "SENSOR addTimeInterval Time:addTimeInterval;" + "\n" +
   61  |             "SENSOR currentTimeBetween Time:currentTimeBetween;" + "\n" +
   62  |          "END SENSORS" + "\n" +
   63  |          "BEGIN EFFECTORS" + "\n" +
   64  |             "EFFECTOR setRandomStartBoundedIntervalAlarm " +
   65  |                "Time:setRandomStartBoundedIntervalAlarm;" + "\n" +
   66  |             "EFFECTOR setEndBoundedIntervalAlarm " +
   67  |                "Time:setEndBoundedIntervalAlarm;" + "\n" +
   68  |             "EFFECTOR setRandomBoundedIntervalAlarm " +
   69  |                "Time:setRandomBoundedIntervalAlarm;" + "\n" +
   70  |             "EFFECTOR EMailWithSubject SampMail:EMailWithSubject;" + "\n" +
   71  |             "EFFECTOR SetMessage Messages:SetMessage;" + "\n" +
   72  |          "END EFFECTORS";
   73  |
   74  |   //--------------------------------------------------------------------------//
   75  |   // Implementation of IAAgent virtual functions                              //
   76  |   //--------------------------------------------------------------------------//
   77  |
   78  |   // Constructor
   79  |  *RemAgent(String fn) throws Exception {
   80  |  |
   81  |  |   super();
   82  |  |    cfgFileName = new String(fn);
   83  |  |   // our concrete implementation of abstract IAAgent - AnAgent
   84  |  |   theAgent=this;
   85  |  |
   86  |  |   // Setup and configure the agent
   87  |  |   if (!setupAgent()) throw new Exception("Agent setup failed");
   88  |  |
   89  |  |   // start the agent - IAAgent start
   90  |  |   // once all components added and adapters and engines are connected)
   91  |  |  *try {
   92  |  |  |   theAgent.start();
   93  |  | **} catch (Exception e) {
   94  |  | |    System.out.println("Agent program exception " + e.getMessage());
   95  |  | |    e.printStackTrace();
   96  |  | |    throw e;
   97  |  | * }
   98  |  |
   99  |  |   // Start the reminders server, listen on default port
  100  |  |   server = new Server(0,appLibrary);
  101  |  *}
  102  |
  103  |   // End of IAAgent virtual function implementation
  104  |
  105  |   // Main: Expects the configuration file name as an argument
  106  |  *public static void main(String args[]) {
  107  |  |  *if (args.length == 1) {
  108  |  |  |
  109  |  |  |   // Get filename to use for list of adapters is input to this agent
  110  |  |  |   // i.e, the configuration file for this agent filename.cfg specified
  111  |  |  |   // by the user.
  112  |  |  |   System.out.println("filename= "+ args[0]);
  113  |  |  |  *try {
  114  |  |  |  |   new RemAgent(args[0]);
  115  |  |  | **} catch (Exception e) {
  116  |  |  | |   System.exit(1);
  117  |  |  | * }
  118  |  | **} else {
  119  |  | |    System.out.println("Usage: java RemAgent configuration_file_name");
  120  |  | |    System.exit(1);
  121  |  | * }
  122  |  *}
  123  |
  124  |  *public boolean setupAgent() {
  125  |  |
  126  |  |   // Handles for: 1)Inference Engine, 2)Persistent storage library
  127  |  |
  128  |  |   engineHandle = new IAEngineHandle();
  129  |  |   libHandle = new IALibraryHandle();
  130  |  |   BufferedReader input = null;
  131  |  |
  132  |  |  *try {
  133  |  |  |   input = new BufferedReader(new FileReader(cfgFileName));
  134  |  |  |
  135  |  |  |   if (!addEngine(engineHandle)) return false;
  136  |  |  |   if (!addLibrary(input, libHandle)) return false;
  137  |  |  |   if (!addAdapters(input)) return false;
  138  |  |  |
  139  |  |  |   preloadCS();                      // Load existing conduct sets
  140  |  |  |
  141  |  | **} catch (Exception e) {
  142  |  | |    System.out.println("Setting up agent exception "+e.getMessage());
  143  |  | |    e.printStackTrace();
  144  |  | |    return false;
  145  |  | * }
  146  |  |   return true;
  147  |  *}   // end setup()
  148  |
  149  |  *private boolean addEngine(IAEngineHandle engineHandle) {
  150  |  |   // ADDING THE ENGINE:
  151  |  |   // First add the engine - we only have RAISE, so this is hard-coded
  152  |  |   // kind = "RAISE" , module_name="iagerais", empty string for parms
  153  |  |   System.out.println("Adding engine RAISE");
  154  |  |  *try {
  155  |  |  |   theAgent.addEngine("RAISE","iagerais","",engineHandle);
  156  |  | **} catch (IAError e) {
  157  |  | |    System.out.println("Engine setup exception "+e.getMessage());
  158  |  | |    e.printStackTrace();
  159  |  | |    return false;
  160  |  | * }
  161  |  |   return true;
  162  |  *}   // end addEngine
  163  |
  164  |   private boolean addLibrary(BufferedReader input,
  165  |  *                           IALibraryHandle libHandle) {
  166  |  |   //Declare library parms
  167  |  |
  168  |  |   String map = null; // Map to library within file system
  169  |  |   String top = null; // Name of top collector in library (top directory)
  170  |  |   String library_type = null; // Library implementation is a file system
  171  |  |   String library_implementation_dll = null; // Dll containing implementation of library
  172  |  |   int numLevels; // Number of Collectors levels in the Library
  173  |  |
  174  |  |   // fill library parms from cfg file.  Cfg file is also used to add Adapters.
  175  |  |   // The cfg file is: cfgFileName.cfg
  176  |  |   // that is provided as a command line parameter input
  177  |  |   // The contents of the library and adapter lines in the cfg file is the same
  178  |  |   // as described for the standard ABE sample agent - refer to
  179  |  |   // Configuration File for the Sample Agent Programs in the ABE User's Guide.
  180  |  |
  181  |  |   String line;
  182  |  |   StringTokenizer tokens;
  183  |  |   String currentToken=new String();
  184  |  |
  185  |  |  *try {
  186  |  |  |
  187  |  |  |// Read, tokenize and store values for library parms from cfg file
  188  |  |  |
  189  |  |  |   line = input.readLine();
  190  |  |  |  *if ( null != line ) {
  191  |  |  |  |   tokens = new StringTokenizer(line); //default delimiter is " \t\n\r"
  192  |  |  |  |
  193  |  |  |  |   // read line data w/o \r\n
  194  |  |  |  |   if (tokens.hasMoreTokens())
  195  |  |  |  |      currentToken = new String(tokens.nextToken());
  196  |  |  |  |   System.out.println("key= " + currentToken);
  197  |  |  |  |  *if (currentToken.equals("library")) {
  198  |  |  |  |  |
  199  |  |  |  |  |   // next token is library type
  200  |  |  |  |  |   library_type=new String(tokens.nextToken());
  201  |  |  |  |  |
  202  |  |  |  |  |   // next token is library module name
  203  |  |  |  |  |   library_implementation_dll=new String(tokens.nextToken());
  204  |  |  |  |  |
  205  |  |  |  |  |   // next token library map
  206  |  |  |  |  |   map=new String(tokens.nextToken());
  207  |  |  |  |  |
  208  |  |  |  |  |   // next token library top collector
  209  |  |  |  |  |   top=new String(tokens.nextToken());
  210  |  |  |  |  |
  211  |  |  |  |  |   // next token number of Collector levels
  212  |  |  |  |  |   numLevels=(Integer.decode(new String(tokens.nextToken()))).intValue();
  213  |  |  |  |  |
  214  |  |  |  |  |   // Add library to the engine
  215  |  |  |  |  |   System.out.println("Adding library");
  216  |  |  |  |  |   theAgent.addLibrary(map, top, library_implementation_dll,
  217  |  |  |  |  |                   library_type, numLevels, libHandle);
  218  |  |  |  |  |
  219  |  |  |  |  |   // libHandle returned by addLibrary represents the new instance of the
  220  |  |  |  |  |   // library added to the current agent.
  221  |  |  |  |  |
  222  |  |  |  |  |   // Previously the addLibrary established the library component of the
  223  |  |  |  |  |   //   agent.  Now we are going to establish an interface to the same
  224  |  |  |  |  |   //   library for direct use by the application for adding new rules
  225  |  |  |  |  |   //   etc. while the agent is running.  The anchor for the application
  226  |  |  |  |  |   //   use of the library is an IALibrary object.  We construct it; then
  227  |  |  |  |  |   //   use IALibary.attachImplementation() to complete its association with
  228  |  |  |  |  |   //   the same inferencing library that the agent is employing.  Because the
  229  |  |  |  |  |   //   library is truly the same as the one used by the agent, we can also
  230  |  |  |  |  |   //   employ the same parameter values as used for addLibary above.
  231  |  |  |  |  |
  232  |  |  |  |  |   // Create library object
  233  |  |  |  |  |   appLibrary = new IALibrary();
  234  |  |  |  |  |
  235  |  |  |  |  |   appLibrary.attachImplementation(map,
  236  |  |  |  |  |                       library_type,
  237  |  |  |  |  |                       library_implementation_dll,
  238  |  |  |  |  |                       top,
  239  |  |  |  |  |                       numLevels);
  240  |  |  |  |  |
  241  |  |  |  |  |   // Create and access the top collector object
  242  |  |  |  |  |
  243  |  |  |  |  |      appTopCollector = appLibrary.getTop();
  244  |  |  |  |  |      appTopCollector.get();
  245  |  |  |  |  |
  246  |  |  |  | **} else {
  247  |  |  |  | |     System.out.println("\nLibrary statement must be first line in " + cfgFileName);
  248  |  |  |  | |     return false;
  249  |  |  |  | * }  // End of token != Library
  250  |  |  | **} else {
  251  |  |  | |    System.out.println("\nLibrary statement must be first line in " + cfgFileName);
  252  |  |  | |    return false;
  253  |  |  | * }  // End of (line == null)
  254  |  |  *}
  255  |  |  *catch (IAError e) {
  256  |  |  |   System.out.println("Library setup exception "+e.getMessage());
  257  |  |  |   e.printStackTrace();
  258  |  |  |   return false;
  259  |  |  *}
  260  |  |   // Catch fileNotFoundException, NumberFormatException, and IOException
  261  |  |  *catch (Exception e) {
  262  |  |  |   System.out.println("Library setup exception "+e.getMessage());
  263  |  |  |   e.printStackTrace();
  264  |  |  |   return false;
  265  |  |  *}
  266  |  |   return true;
  267  |  *}  // end of addLibrary
  268  |
  269  |  *private boolean addAdapters(BufferedReader input) {
  270  |  |   // ADDING THE ADAPTERS.
  271  |  |   IAAdapterHandle aHandle;
  272  |  |   String domain;
  273  |  |   String moduleName;
  274  |  |   String parms;
  275  |  |   String conductSet;
  276  |  |   String selector;
  277  |  |
  278  |  |   String line;
  279  |  |   StringTokenizer tokens;
  280  |  |   String currentToken=new String();
  281  |  |
  282  |  |  *try {
  283  |  |  |   boolean endAdapters=false;
  284  |  |  |
  285  |  |  |   // loop and read adapters names from file,
  286  |  |  |   // add each adapter and connect it to the engine
  287  |  |  |   // format of cfg file is:
  288  |  |  |   // key1<tab>domain1<tab>module_name1<tab>parms1
  289  |  |  |   // key2<tab>domain2<tab>module_name2<tab>parms2
  290  |  |  |   // etc.. - again the same as the configuration file for the ABE sample agent.
  291  |  |  |   // ex: Adapter<tab>Time<tab>iagatime
  292  |  |  |  *while (!endAdapters) {
  293  |  |  |  |   System.out.println("Read first adapter");
  294  |  |  |  |   line = input.readLine();
  295  |  |  |  |   if ( null == line ) break;
  296  |  |  |  |   tokens = new StringTokenizer(line); //default delimiter is " \t\n\r"
  297  |  |  |  |
  298  |  |  |  |   // get keyword ("adapter")
  299  |  |  |  |   // read line data w/o \r\n
  300  |  |  |  |   if (tokens.hasMoreTokens())
  301  |  |  |  |      currentToken = new String(tokens.nextToken());
  302  |  |  |  |   System.out.println("key= " + currentToken);
  303  |  |  |  |  *if (currentToken.equals("adapter")) {
  304  |  |  |  |  |
  305  |  |  |  |  |   // next token is adapter domain
  306  |  |  |  |  |   domain=new String(tokens.nextToken());
  307  |  |  |  |  |
  308  |  |  |  |  |   // next token is adapter module name
  309  |  |  |  |  |   moduleName=new String(tokens.nextToken());
  310  |  |  |  |  |
  311  |  |  |  |  |   // next token is parms for the adapter (if they exist)
  312  |  |  |  |  |
  313  |  |  |  |  |   // Note:  The tokenizer is parsing on 4 values (blank, \n, \t,
  314  |  |  |  |  |   // \r) so we don't really know how the adapter parm data is
  315  |  |  |  |  |   // delimitted.  However, since the Message adapter is the only
  316  |  |  |  |  |   // one with parms for this agent, and it's parms are expected
  317  |  |  |  |  |   // to be blank-delimited, we can safely blank-delimit the parm
  318  |  |  |  |  |   // list that we build.
  319  |  |  |  |  |
  320  |  |  |  |  |  *if (tokens.hasMoreTokens()) {
  321  |  |  |  |  |  |   parms=new String(tokens.nextToken());
  322  |  |  |  |  |  |  *while (tokens.hasMoreTokens()){
  323  |  |  |  |  |  |  |  parms += " " + tokens.nextToken();
  324  |  |  |  |  |  |  *  }
  325  |  |  |  |  |  *   }
  326  |  |  |  |  |   else parms=new String("");
  327  |  |  |  |  |
  328  |  |  |  |  |   // add the adapter and connect it to the engine
  329  |  |  |  |  |   aHandle=new IAAdapterHandle();
  330  |  |  |  |  |   theAgent.addAdapter(domain,moduleName,parms,aHandle);
  331  |  |  |  |  |   theAgent.connect(aHandle,engineHandle);
  332  |  |  |  |  *}
  333  |  |  |  |   else endAdapters=true;
  334  |  |  |  *} //end-while
  335  |  |  *}
  336  |  |  *catch (Exception e) {
  337  |  |  |   System.out.println("Adapters setup exception "+e.getMessage());
  338  |  |  |   e.printStackTrace();
  339  |  |  |   return false;
  340  |  |  *}
  341  |  |   return true;
  342  |  *}  // end addAdapters
  343  |
  344  |  *boolean preloadCS() {
  345  |  |   IALibInferenceCollector user_collector = null;
  346  |  |   IALibInferenceContentsElement current_collector_element = null;
  347  |  |   IALibInferenceContentsElement current_ruleset_element = null;
  348  |  |   IALibInferenceRuleSet user_ruleset = null;
  349  |  |
  350  |  |  *try {
  351  |  |  |  //   Find all user collectors, and their rulesets so that we can
  352  |  |  |  //   initialize the agent.  That is, we need to establish
  353  |  |  |  //   alarms for all of the reminders that we had in the
  354  |  |  |  //   system when the server was last up.
  355  |  |  |  //
  356  |  |  |  String user_name; //used for user collector, ruleset, and
  357  |  |  |                    //selector names (common name for all)
  358  |  |  |  boolean looper;
  359  |  |  |  String csname;
  360  |  |  |  //
  361  |  |  |  appTopCollector.setCursorElementScope(IALibrary.IALibICCS_collectors);
  362  |  |  |  current_collector_element = appLibrary.new_IALibInferenceContentsElement();
  363  |  |  |  current_ruleset_element = appLibrary.new_IALibInferenceContentsElement();
  364  |  |  |  for(
  365  |  |  |  looper = appTopCollector.firstElement(current_collector_element);
  366  |  |  | *   looper==true;) {
  367  |  |  | |//
  368  |  |  | |user_name = current_collector_element.extractElementName();
  369  |  |  | |user_collector =
  370  |  |  | |    appLibrary.new_IALibInferenceCollector(appTopCollector,user_name);
  371  |  |  | |user_collector.get();
  372  |  |  | |//
  373  |  |  | |//  We cannot assume that finding a collector means
  374  |  |  | |//  that a ruleset exists because we could
  375  |  |  | |//  have a Collector with only messages held for the
  376  |  |  | |//  user to retrieve (has deleted the reminder rules
  377  |  |  | |//  that generated the message!
  378  |  |  | |//
  379  |  |  | |user_collector.setCursorElementScope(IALibrary.IALibICCS_rulesets);
  380  |  |  | |//
  381  |  |  | |if (user_collector.find(current_ruleset_element,user_name,
  382  |  |  | |                      IALibrary.IALibICET_ruleset))
  383  |  |  | *{
  384  |  |  | |//
  385  |  |  | |//   We use user_name above and below because
  386  |  |  | |//   user name, user collector name, ruleset name,
  387  |  |  | |//   and selector name are all the same!
  388  |  |  | |//
  389  |  |  | |user_ruleset = appLibrary.new_IALibInferenceRuleSet(user_collector,
  390  |  |  | |                     user_name);
  391  |  |  | |csname = File.separator + user_name + File.separator + user_name;
  392  |  |  | |
  393  |  |  | |// Note:  We use the application library object to 'find' which
  394  |  |  | |//        rule sets to load, however we pass the Agent's library
  395  |  |  | |//        object handle on the load conduct set since the agent is
  396  |  |  | |//        doing the load.
  397  |  |  | |theAgent.loadConductSet(libHandle, engineHandle,
  398  |  |  | |                         csname, user_name);
  399  |  |  | |//
  400  |  |  | |//  Where lHandle and eHandle were established in the
  401  |  |  | |//  setupAgent() method earlier.  Selector
  402  |  |  | |//  name is the same as collector name (user_name)
  403  |  |  | |//
  404  |  |  | *} // end of the if
  405  |  |  | |looper = appTopCollector.nextElement(current_collector_element);
  406  |  |  | *} // end of the for loop
  407  |  | **} catch (IAError e) {
  408  |  | |    System.out.println("Caught IAError: " + e.errormsg());
  409  |  | |    return false; // Unable to pre-load existing conduct sets
  410  |  | * }
  411  |  |return true;
  412  |  *} // end preloadCs()
  413  |
  414  |
  415  *} //end class RemAgent


Server Class

 
    1   // The Reminders server class:
    2   // 1. Creates a server socket thread that listens for connections from clients
    3   // 2. Once a connection request from a client is received, a Connection
    4   //    thread is started to handle all comm. with client.
    5   //
    6  *class Server extends Thread {
    7  |   public final static int DEFAULT_PORT = 6789;
    8  |   protected int port;
    9  |   protected ServerSocket listen_socket;
   10  |   protected IALibrary library;
   11  |
   12  |   // Exit with an error message when an error occurs.
   13  |  *public static void fail(Exception e, String msg) {
   14  |  |   System.err.println(msg + ": " + e);
   15  |  |   System.exit(1);
   16  |  *}
   17  |
   18  |   // Creat a ServerSocket to listen for connections on;
   19  |   // Start the thread.
   20  |  *public Server(int port, IALibrary library) {
   21  |  |   if (port == 0) port = DEFAULT_PORT;
   22  |  |   this.port = port;
   23  |  |   this.library = library;
   24  |  |  *try {
   25  |  |  |   listen_socket = new ServerSocket(port);
   26  |  |  *}
   27  |  |  *catch (IOException e) {
   28  |  |  |   fail(e, "Exception creating server socket");
   29  |  |  *}
   30  |  |   this.start();
   31  |  *}
   32  |
   33  |   // The body of the server thread. Loop forever, listening for and
   34  |   // accepting connections from clients. For each connection,
   35  |   // create a Connection object to handle communication through the new
   36  |   // socket to the client.
   37  |  *public void run() {
   38  |  |   Socket client_socket;
   39  |  |   Connection c;
   40  |  |  *try {
   41  |  |  |  *while(true) {
   42  |  |  |  |   System.out.println("Server: listening on port " + port);
   43  |  |  |  |   client_socket = listen_socket.accept();
   44  |  |  |  |   c = new Connection(client_socket,library);
   45  |  |  |  *}
   46  |  |  *}
   47  |  |  *catch (IOException e) {
   48  |  |  |   fail(e, "Exception while listening for connections");
   49  |  |  *}
   50  |  *}
   51  |
   52  *}


Connection Class

 
    1   // This class is the thread that handles all communications with a client:
    2   // 1. Opens a socket with the client
    3   // 2. Starts a thread that loops forever, and gets commands from client
    4   //
    5  *class Connection extends Thread {
    6  |   protected Socket client;
    7  |   protected BufferedReader in;
    8  |   protected PrintWriter out;
    9  |   private RemMessageVector msgCollection = new RemMessageVector();
   10  |   private boolean debug = false;
   11  |
   12  |   IALibrary library = null;    // Library object
   13  |
   14  |   // Declare the library objects where rules are saved
   15  |   // Collector object
   16  |   public IALibInferenceCollector top_collector = null;
   17  |
   18  |   // User's collector object
   19  |   public IALibInferenceCollector user_collector = null;
   20  |
   21  |   // Current contents element object
   22  |   public IALibInferenceContentsElement current_collector_element = null;
   23  |
   24  |   // Current contents element object
   25  |   public IALibInferenceContentsElement current_ruleset_element = null;
   26  |
   27  |   // User's rule set object
   28  |   public IALibInferenceRuleSet user_ruleset = null;
   29  |
   30  |   // User's rule object
   31  |   public IALibInferenceRule user_rule = null;
   32  |
   33  |   // Number of rules in user's ruleset
   34  |   int number_of_rules = 0;
   35  |
   36  |   // User ID
   37  |   String userID = "";
   38  |
   39  |   // Initialize the streams and start the threads
   40  |   public Connection(Socket client_socket,
   41  |  *                  IALibrary library) {
   42  |  |   client = client_socket;
   43  |  |   this.library = library;
   44  |  |  *try {
   45  |  |  |  top_collector = library.getTop();
   46  |  | **} catch (IAError e) {
   47  |  | |    System.err.println("Exception while accessing library.");
   48  |  | |    return;
   49  |  | * }
   50  |  |  *try {
   51  |  |  |   in = new BufferedReader(new InputStreamReader(client.getInputStream()));
   52  |  |  |   out = new PrintWriter(client.getOutputStream(), true);
   53  |  |  *}
   54  |  |  *catch (IOException e) {
   55  |  |  |   try {client.close();}
   56  |  |  |   catch (IOException e2){};
   57  |  |  |   System.err.println("Exception while getting socket streams.");
   58  |  |  |   return;
   59  |  |  *}
   60  |  |   this.start();
   61  |  *}
   62  |
   63  |   // Provide the service:
   64  |   // Read a line, form a command, and respond..
   65  |  *public void run() {
   66  |  |   String line, cmd, remID, eventDateString;
   67  |  |   String remsStr, rulesStr, remStr, rule1Str, rule2Str, v1, v2, fn;
   68  |  |   boolean newFlg;
   69  |  |   int i, mode = 5;
   70  |  |   Hashtable remDB = new Hashtable();
   71  |  |   String dbStr = new String();
   72  |  |
   73  |  |
   74  |  |   // Connectionless mode - provide service and return
   75  |  |   // Read in the commands from the client:
   76  |  |   // 1. GET: Return to the client, all reminders for the specified user
   77  |  |   //         in persistant storage
   78  |  |   // syntax= GET:USERID
   79  |  |   // 2. PUT:Stores a reminder in persistant storage and creates rules
   80  |  |   // syntax= PUT:USERID:REMSTRING
   81  |  |   // 2. REMOVE:Removess a reminder and associated rules from storage
   82  |  |   // syntax= REMOVE:USERID:REMID
   83  |  |   // 3. MODIFY: Same as a remove followed by a put.
   84  |  |   // 4. GETMSGS: Return to the client all messages for the specified
   85  |  |   //             user in persistent storage, and markr returned messages
   86  |  |   //             as read.
   87  |  |   // syntax=GETMSGS:USERID
   88  |  |   // 5. GETMSGSNOMARK: Return to the client all messages for the specified
   89  |  |   //             user in persistent storage, but do not mark returned
   90  |  |   //             messages as read.
   91  |  |   // syntax=GETMSGSNOMARK:USERID
   92  |  |   // 6. DELMSGS: Removes specified messages for the specified user from
   93  |  |   //             persistent storage.
   94  |  |   // syntax=DELMSGS:USERID:MSGID,MSGID,MSGID,...
   95  |  |   // 7. MARKMSGSASNEW: Marks all messages for the specified user
   96  |  |   //                   as not read.
   97  |  |   // syntax=MARKMSGSASNEW:USERID:MSGID,MSGID,...
   98  |  |   // 8. STATUSMSGS: Returns true if new messages exist for the specified
   99  |  |   //                user in persistent storage.
  100  |  |   // syntax=STATUSMSGS:USERID
  101  |  |
  102  |  |  *try {
  103  |  |  |  *for(;;) {
  104  |  |  |  |
  105  |  |  |  |   // Read in the message line from the client
  106  |  |  |  |   line = in.readLine();
  107  |  |  |  |   System.out.println("Client: " + line);
  108  |  |  |  |  *if (line == null) {
  109  |  |  |  |  |   out.println("ERROR:01");
  110  |  |  |  |  |   System.out.println("Server: null command from client!");
  111  |  |  |  |  |   break;
  112  |  |  |  |  *}
  113  |  |  |  |
  114  |  |  |  |   // 1. Parse the command: cmnd:userID:v1
  115  |  |  |  |   StringTokenizer st = new StringTokenizer(line, ":");
  116  |  |  |  |   cmd = st.nextToken().toUpperCase();
  117  |  |  |  |   System.out.println("Server: CMD= " + cmd);
  118  |  |  |  |  *if(!st.hasMoreTokens()&& !cmd.equals("QUIT")) {
  119  |  |  |  |  |   out.println("ERROR:02");
  120  |  |  |  |  |   System.out.println("Server: Message without user ID..");
  121  |  |  |  |  |    break;
  122  |  |  |  |  *}
  123  |  |  |  |
  124  |  |  |  |   // 2nd. token should be the user's ID
  125  |  |  |  |   if( !cmd.equals( "QUIT" ) )
  126  |  |  |  |    *{
  127  |  |  |  |    |userID = st.nextToken();
  128  |  |  |  |    |System.out.println("Server: " + cmd + " " + userID);
  129  |  |  |  |    *}
  130  |  |  |  |
  131  |  |  |  |  *if (cmd.indexOf("MSGS") == -1 && !cmd.equals( "QUIT" )) {
  132  |  |  |  |  |  // Setup rules access.. mode will tell us if new user,
  133  |  |  |  |  |  // if user has a collector, or any rules
  134  |  |  |  |  |  mode = setupRulesAccess(userID,cmd);
  135  |  |  |  |  |  System.out.println("mode= " + mode);
  136  |  |  |  |  | *if ( mode > 2 ) {
  137  |  |  |  |  | |
  138  |  |  |  |  | |   // modes 5, 4 are errors: can't create; 3 is new collector
  139  |  |  |  |  | |   // top collector, user's collector, or user's rule-set respectively.
  140  |  |  |  |  | |   out.println("ERROR:03");
  141  |  |  |  |  | |   break;
  142  |  |  |  |  | *}
  143  |  |  |  |  *}
  144  |  |  |  |
  145  |  |  |  |   // service the command
  146  |  |  |  |   // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GET %%%%%%%%%%%%%%%%%%%%%%%%
  147  |  |  |  |  *if (cmd.equals("GET")) {
  148  |  |  |  |  |   System.out.println("Server: GET command.. ");
  149  |  |  |  |  |  *if (0 == mode) {
  150  |  |  |  |  |  |
  151  |  |  |  |  |  |   // user already has collector & a rule set; get the rules
  152  |  |  |  |  |  |   remsStr = getUserRules();
  153  |  |  |  |  |  |  *if (null != remsStr) {
  154  |  |  |  |  |  |  |
  155  |  |  |  |  |  |  |
  156  |  |  |  |  |  |  |   //return reminders to the client
  157  |  |  |  |  |  |  |   out.println("GET:" + remsStr);
  158  |  |  |  |  |  |  |   System.out.println("User " + userID + " reminders: ");
  159  |  |  |  |  |  |  |   System.out.println(remsStr);
  160  |  |  |  |  |  | **} else {
  161  |  |  |  |  |  | |
  162  |  |  |  |  |  | |    // user has no saved reminders
  163  |  |  |  |  |  | |    // respond with LOGON cmnd w/o rules
  164  |  |  |  |  |  | |    out.println("GET:");
  165  |  |  |  |  |  | * }
  166  |  |  |  |  | **} else if (2 == mode) {
  167  |  |  |  |  | |
  168  |  |  |  |  | |    // user has an empty rule set.
  169  |  |  |  |  | |    // respond with LOGON cmnd w/o rules
  170  |  |  |  |  | |    out.println("GET:");
  171  |  |  |  |  | |    System.out.println("Server: empty ruleset.. ");
  172  |  |  |  |  | * }
  173  |  |  |  |  |   break;
  174  |  |  |  |  |
  175  |  |  |  |  |// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PUT %%%%%%%%%%%%%%%%%%%%%%%%
  176  |  |  |  | **} else if (cmd.equals("PUT")) {
  177  |  |  |  | |    System.out.println("Server: PUT command.. ");
  178  |  |  |  | |   *if(!st.hasMoreTokens()) {
  179  |  |  |  | |   |   out.println("ERROR:05");
  180  |  |  |  | |   |   System.out.println("Server: PUT without parms..");
  181  |  |  |  | |   |   break;
  182  |  |  |  | |   *}
  183  |  |  |  | |
  184  |  |  |  | |    //Command format is: PUT:remMsgStr where remMsgStr is:
  185  |  |  |  | |    // ID$remID$remStr
  186  |  |  |  | |    v1 = st.nextToken();
  187  |  |  |  | |    StringTokenizer st1 = new StringTokenizer(v1, "$");
  188  |  |  |  | |   *if(!st1.nextToken().equals("ID")) {
  189  |  |  |  | |   |   System.out.println("Server: PUT command error: ");
  190  |  |  |  | |   |   System.out.println("Server: No ID field received in reminder.");
  191  |  |  |  | |   |   out.println("ERROR:06");
  192  |  |  |  | |   |   break;
  193  |  |  |  | |   *}
  194  |  |  |  | |
  195  |  |  |  | |    // Get reminder ID, reminder string, convert to KIF rule
  196  |  |  |  | |    // format, and save in library.
  197  |  |  |  | |    remID = st1.nextToken();
  198  |  |  |  | |    System.out.println("Server: ID= " + remID);
  199  |  |  |  | |    remStr = st1.nextToken();
  200  |  |  |  | |
  201  |  |  |  | |    //If a brand new reminder, create a new rem ID
  202  |  |  |  | |   *if ( remID.equals("000") ) {
  203  |  |  |  | |   |   remID = createUniqueID();
  204  |  |  |  | |   |
  205  |  |  |  | |   |   // update the reminder string with the new ID
  206  |  |  |  | |   |   remStr = "ID=" + remID + "#" + remStr;
  207  |  |  |  | |   *}
  208  |  |  |  | |    System.out.println(remStr);
  209  |  |  |  | |   *if (0 == user_ruleset.size()) {
  210  |  |  |  | |   |   newFlg = true;
  211  |  |  |  | |   *}
  212  |  |  |  | |   *else {
  213  |  |  |  | |   |   newFlg = false;
  214  |  |  |  | |   *}
  215  |  |  |  | |   *if (saveReminderInLibrary(remID, remStr, newFlg)) {
  216  |  |  |  | |   |
  217  |  |  |  | |   |   // Get the rules string (meta data) and return it..
  218  |  |  |  | |   |   System.out.println("Get user rules..");
  219  |  |  |  | |   |   remsStr = getUserRules();
  220  |  |  |  | |   |   System.out.println("To the Client >>>>>>>>>>>>>>>>>>>>>");
  221  |  |  |  | |   |   System.out.println("PUT:" + remsStr);
  222  |  |  |  | |   |   out.println("PUT:" + remsStr);
  223  |  |  |  | |  **} else {
  224  |  |  |  | |  |    System.out.println("Error saving Reminder..");
  225  |  |  |  | |  |    out.println("ERROR:07");
  226  |  |  |  | |  |    break;
  227  |  |  |  | |  * }
  228  |  |  |  | |    break;
  229  |  |  |  | | // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MODIFY %%%%%%%%%%%%%%%%%%%%%%%%
  230  |  |  |  |** } else if (cmd.equals("MODIFY")) {
  231  |  |  |  ||     System.out.println("Server: MODIFY command.. ");
  232  |  |  |  ||
  233  |  |  |  ||     //Command format is: MODIFY:userID:remMsgStr where remMsgStr is:
  234  |  |  |  ||     // ID$remID$remStr
  235  |  |  |  ||     v1 = st.nextToken();
  236  |  |  |  ||     StringTokenizer st1 = new StringTokenizer(v1, "$");
  237  |  |  |  ||    *if(!st1.nextToken().equals("ID")) {
  238  |  |  |  ||    |   System.out.println("Server: MODIFY command error: ");
  239  |  |  |  ||    |   System.out.println("Server: No ID field received in reminder.");
  240  |  |  |  ||    |   out.println("ERROR:08");
  241  |  |  |  ||    |   break;
  242  |  |  |  ||    *}
  243  |  |  |  ||
  244  |  |  |  ||     // Get reminder ID, reminder string, convert to KIF rule
  245  |  |  |  ||     // format, and save in library.
  246  |  |  |  ||     remID = st1.nextToken();
  247  |  |  |  ||     System.out.println("Server: ID= " + remID);
  248  |  |  |  ||     remStr = st1.nextToken();
  249  |  |  |  ||
  250  |  |  |  ||     // restore the reminder ID to reminder string
  251  |  |  |  ||     remStr = "ID=" + remID + "#" + remStr;
  252  |  |  |  ||     System.out.println(remStr);
  253  |  |  |  ||
  254  |  |  |  ||     // 1st remove existing rule, then save new one
  255  |  |  |  ||     newFlg = false;
  256  |  |  |  ||    *if (deleteReminderFromLibrary(remID)) {
  257  |  |  |  ||    |  *if (saveReminderInLibrary(remID, remStr, newFlg)) {
  258  |  |  |  ||    |  |
  259  |  |  |  ||    |  |   // Get the rules string (meta data) and return it..
  260  |  |  |  ||    |  |   System.out.println("Get user rules..");
  261  |  |  |  ||    |  |   remsStr = getUserRules();
  262  |  |  |  ||    |  |   System.out.println("To the Client >>>>>>>>>>>>>>>>>>>>>");
  263  |  |  |  ||    |  |   System.out.println("MODIFY:" + remsStr);
  264  |  |  |  ||    |  |   out.println("MODIFY:" + remsStr);
  265  |  |  |  ||    | **} else {
  266  |  |  |  ||    | |    System.out.println("Error saving Reminder..");
  267  |  |  |  ||    | |    out.println("ERROR:08");
  268  |  |  |  ||    | |    break;
  269  |  |  |  ||    | * }
  270  |  |  |  ||   **} else {
  271  |  |  |  ||   |    System.out.println("Error deleting reminder..");
  272  |  |  |  ||   |    out.println("ERROR:09");
  273  |  |  |  ||   |    break;
  274  |  |  |  ||   * }
  275  |  |  |  ||     break;
  276  |  |  |  ||  // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% REMOVE %%%%%%%%%%%%%%%%%%%%%%%%
  277  |  |  |  **  } else if (cmd.equals("REMOVE")) {
  278  |  |  |  |
  279  |  |  |  |      // SYNTAX= REMOVE:USER_ID:REMINDER_ID
  280  |  |  |  |      System.out.println("Server: REMOVE command.. ");
  281  |  |  |  |     *if(!st.hasMoreTokens()) {
  282  |  |  |  |     |   System.out.println("Server: REMOVE without reminder ID..");
  283  |  |  |  |     |   out.println("ERROR:10");
  284  |  |  |  |     |   break;
  285  |  |  |  |     *}
  286  |  |  |  |
  287  |  |  |  |      remID = st.nextToken();
  288  |  |  |  |      System.out.println("Server: REMOVE: " + userID + " " + remID);
  289  |  |  |  |
  290  |  |  |  |     *if (deleteReminderFromLibrary(remID)) {
  291  |  |  |  |     |   String csName = File.separator + userID + File.separator + userID;
  292  |  |  |  |     |
  293  |  |  |  |     |   // check if ruleset is empty
  294  |  |  |  |     |  *if (0 == user_ruleset.size()) {
  295  |  |  |  |     |  |
  296  |  |  |  |     |  |   // unload conduct set and delete collector
  297  |  |  |  |     |  |  *try {
  298  |  |  |  |     |  |  |
  299  |  |  |  |     |  |  |   // We reset the user BEFORE we try to delete
  300  |  |  |  |     |  |  |   // the collector.  This is to make sure no new
  301  |  |  |  |     |  |  |   // messages get generated after/during the collector
  302  |  |  |  |     |  |  |   // delete.
  303  |  |  |  |     |  |  |
  304  |  |  |  |     |  |  |   RemAgent.theAgent.reset(userID);
  305  |  |  |  |     |  |  |
  306  |  |  |  |     |  |  |   // Delete rule set and rule set metadata from
  307  |  |  |  |     |  |  |   // persistent storage
  308  |  |  |  |     |  |  |
  309  |  |  |  |     |  |  |   user_ruleset.del();
  310  |  |  |  |     |  |  |
  311  |  |  |  |     |  |  |   // Now delete the user collector, since it is empty
  312  |  |  |  |     |  |  |   // Check to see if any messages for this user (any
  313  |  |  |  |     |  |  |   // collector metadata) and delete collector from
  314  |  |  |  |     |  |  |   // persistent storage if no messages (since no rules
  315  |  |  |  |     |  |  |   // exist either).
  316  |  |  |  |     |  |  |   // Note that our version of the metadata may be
  317  |  |  |  |     |  |  |   // outdated (the metadata on persistent storage may
  318  |  |  |  |     |  |  |   // have changed since we did our 'get' of it).
  319  |  |  |  |     |  |  |
  320  |  |  |  |     |  |  |  *if (user_collector.extractMetadata().equals("")) {
  321  |  |  |  |     |  |  |  |  *try {
  322  |  |  |  |     |  |  |  |  | *synchronized (top_collector) {
  323  |  |  |  |     |  |  |  |  | |  user_collector.del();
  324  |  |  |  |     |  |  |  |  | *  }
  325  |  |  |  |     |  |  |  | **} catch (IAError e) {
  326  |  |  |  |     |  |  |  | | if (e.msgnumber() !=
  327  |  |  |  |     |  |  |  | |     IAError.IA_E_LIBRARY_VERSION_ERROR)
  328  |  |  |  |     |  |  |  | |   throw e;    // Not version mismatch, throw error
  329  |  |  |  |     |  |  |  | * }
  330  |  |  |  |     |  |  |  *}
  331  |  |  |  |     |  | **} catch (IAError e) {
  332  |  |  |  |     |  | |    System.out.println("Remove Rule- Caught IAError: " + e.errormsg());
  333  |  |  |  |     |  | |    out.println("ERROR:11");
  334  |  |  |  |     |  | |    break;
  335  |  |  |  |     |  | * }
  336  |  |  |  |     | **} else {
  337  |  |  |  |     | |   *try {
  338  |  |  |  |     | |   |   user_ruleset.put();
  339  |  |  |  |     | |   |
  340  |  |  |  |     | |   |   // load the new conduct set
  341  |  |  |  |     | |   |   RemAgent.theAgent.reset(userID);
  342  |  |  |  |     | |   |   RemAgent.theAgent.loadConductSet(RemAgent.libHandle,
  343  |  |  |  |     | |   |                RemAgent.engineHandle, csName, userID);
  344  |  |  |  |     | |  **} catch (IAError e) {
  345  |  |  |  |     | |  |    System.out.println("Remove Rule- Caught IAError: " + e.errormsg());
  346  |  |  |  |     | |  |    out.println("ERROR:12");
  347  |  |  |  |     | |  |    break;
  348  |  |  |  |     | |  * }
  349  |  |  |  |     | * }
  350  |  |  |  |     |
  351  |  |  |  |     |   // Get the rules string (meta data) and return it..
  352  |  |  |  |     |   System.out.println("Get user rules..");
  353  |  |  |  |     |   remsStr = getUserRules();
  354  |  |  |  |     |   System.out.println("To the Client >>>>>>>>>>>>>>>>>>>>>");
  355  |  |  |  |     |   System.out.println("REMOVE:" + remsStr);
  356  |  |  |  |     |   out.println("REMOVE:" + remsStr);
  357  |  |  |  |    **} else {
  358  |  |  |  |    |    System.out.println("Server: Error deleting reminder..");
  359  |  |  |  |    |    out.println("ERROR:13");
  360  |  |  |  |    |    break;
  361  |  |  |  |    * }
  362  |  |  |  |      break;
  363  |  |  |  |   // %%%%%%%%%%%%%%%%%%%%%%%%%%% GET ALL MESSAGES %%%%%%%%%%%%%%%%%%%
  364  |  |  | **   } else if (cmd.equals("GETMSGS")) {
  365  |  |  | ||      System.out.println("Server: GET ALL MESSAGES command.. ");
  366  |  |  | ||      // user already has collector & a message set; get the msgs
  367  |  |  | ||      remsStr = convertNLs(getMsgs(userID, true));
  368  |  |  | ||     *if (null != remsStr) {
  369  |  |  | ||     |
  370  |  |  | ||     |   //return reminders to the client
  371  |  |  | ||     |   out.println(cmd + ":" + remsStr + "\n" );
  372  |  |  | ||     |   System.out.println("User " + userID + " messages: ");
  373  |  |  | ||     |   System.out.println(remsStr);
  374  |  |  | ||    **} else {
  375  |  |  | ||    |
  376  |  |  | ||    |    // user has no saved reminders
  377  |  |  | ||    |    // respond with current command name with no messages
  378  |  |  | ||    |    out.println(cmd + ":");
  379  |  |  | ||    * }
  380  |  |  | ||      break;
  381  |  |  | ||
  382  |  |  | ||   // %%%%%%%%%%%%%%%%%%%%%%%% GET MESSAGES NO MARK %%%%%%%%%%%%%%%%%%
  383  |  |  | **   } else if (cmd.equals("GETMSGSNOMARK")) {
  384  |  |  | |       System.out.println("Server: GET ALL MESSAGES NO MARK command.. ");
  385  |  |  | |       // user already has collector & a message set; get the msgs
  386  |  |  | |       remsStr = convertNLs(getMsgs(userID, false));
  387  |  |  | |      *if (null != remsStr) {
  388  |  |  | |      |
  389  |  |  | |      |   //return reminders to the client
  390  |  |  | |      |   out.println(cmd + ":" + remsStr + "\n" );
  391  |  |  | |      |   System.out.println("User " + userID + " messages: ");
  392  |  |  | |      |   System.out.println(remsStr);
  393  |  |  | |     **} else {
  394  |  |  | |     |
  395  |  |  | |     |    // user has no saved reminders
  396  |  |  | |     |    // respond with current command name with no messages
  397  |  |  | |     |    out.println(cmd + ":");
  398  |  |  | |     * }
  399  |  |  | |       break;
  400  |  |  | |    // %%%%%%%%%%%%%%%%%%%%%%%%%%% DELETE MESSAGES %%%%%%%%%%%%%%%%%%%%
  401  |  |  |**    } else if (cmd.equals("DELMSGS")) {
  402  |  |  |||       System.out.println("Server: DELETE ALL MESSAGES command.. ");
  403  |  |  |||       // user already has collector & a message set; delete  msgs
  404  |  |  |||       v1 = st.nextToken();
  405  |  |  |||       remsStr = deleteMsgs(userID, v1);
  406  |  |  |||      *if (null != remsStr) {
  407  |  |  |||      |
  408  |  |  |||      |   //return reminders to the client
  409  |  |  |||      |   out.println(cmd + ":" + remsStr + "\n" );
  410  |  |  |||      |   System.out.println("User " + userID + " messages: ");
  411  |  |  |||      |   System.out.println(remsStr);
  412  |  |  |||     **} else {
  413  |  |  |||     |
  414  |  |  |||     |    // user has no saved reminders
  415  |  |  |||     |    // respond with current command name with no messages
  416  |  |  |||     |    out.println(cmd + ":");
  417  |  |  |||     * }
  418  |  |  |||       break;
  419  |  |  |||    // %%%%%%%%%%%%%%%%%%%%%%%%%% MARK MESSAGES NEW %%%%%%%%%%%%%%%%%%%
  420  |  |  |**    } else if (cmd.equals("MARKMSGSASNEW")) {
  421  |  |  ||        System.out.println("Server: GET NEW MESSAGES command.. ");
  422  |  |  ||        // user already has collector & a message set; delete  msgs
  423  |  |  ||        v1 = st.nextToken();
  424  |  |  ||        remsStr = markMsgs(userID, v1);
  425  |  |  ||       *if (null != remsStr) {
  426  |  |  ||       |
  427  |  |  ||       |   //return reminders to the client
  428  |  |  ||       |   out.println(cmd + ":" + remsStr + "\n" );
  429  |  |  ||       |   System.out.println("User " + userID + " messages: ");
  430  |  |  ||       |   System.out.println(remsStr);
  431  |  |  ||      **} else {
  432  |  |  ||      |
  433  |  |  ||      |    // user has no saved reminders
  434  |  |  ||      |    // respond with current command name with no messages
  435  |  |  ||      |    out.println(cmd + ":");
  436  |  |  ||      * }
  437  |  |  ||        break;
  438  |  |  ||     // %%%%%%%%%%%%%%%%%%%%%%%% QUERY IF NEW MESSAGES %%%%%%%%%%%%%%%%%
  439  |  |  **     } else if (cmd.equals("STATUSMSGS")) {
  440  |  |  ||        System.out.println("Server: QUERY NEW MESSAGES command.. ");
  441  |  |  ||        // user already has collector & a message set; get the msgs
  442  |  |  ||        remsStr = newMsgs(userID);
  443  |  |  ||       *if (null != remsStr) {
  444  |  |  ||       |
  445  |  |  ||       |   //return reminders to the client
  446  |  |  ||       |   out.println(cmd + ":" + remsStr + "\n" );
  447  |  |  ||       |   System.out.println("User " + userID + " messages: ");
  448  |  |  ||       |   System.out.println(remsStr);
  449  |  |  ||      **} else {
  450  |  |  ||      |
  451  |  |  ||      |    // user has no saved reminders
  452  |  |  ||      |    // respond with current command name with no messages
  453  |  |  ||      |    out.println(cmd + ":");
  454  |  |  ||      * }
  455  |  |  ||        break;
  456  |  |  ||
  457  |  |  ||
  458  |  |  ||     // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% QUIT %%%%%%%%%%%%%%%%%%%%%%%%%%
  459  |  |  **     } else if (cmd.equals("QUIT")) {
  460  |  |  |        // The msgConnection code uses this to terminate the read loop
  461  |  |  |        // from the socket...
  462  |  |  |         System.out.println("QUIT: client terminated connection.. ");
  463  |  |  |         break;
  464  |  |  |
  465  |  |  |      // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OK %%%%%%%%%%%%%%%%%%%%%%%%%%%%
  466  |  | **      } else if (cmd.equals("OK")) {
  467  |  | ||         System.out.println("OK: client received response.. ");
  468  |  | ||         break;
  469  |  | ||
  470  |  | ||      // all other commands..
  471  |  | ||      // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% UNKNOWN %%%%%%%%%%%%%%%%%%%%%%%%
  472  |  | **      } else {
  473  |  | ||         System.out.println("Server: unknown command.. ");
  474  |  | ||         out.println("ERROR:14");
  475  |  | ||         break;
  476  |  | |*      }
  477  |  | *    } //end for
  478  |  | * } catch (IOException e){};
  479  |  |   try {client.close();} catch (IOException e2){};
  480  |  |   System.out.println("Done! Close the connection..");
  481  |  *} //end run() thread
  482  |
  483  |
  484  |   // *************************************************************************
  485  |   // Setup user's rules access from persistant storage..
  486  |  *int setupRulesAccess(String usr, String cmd) {
  487  |  |boolean newUser = true;
  488  |  |
  489  |  |  *try {
  490  |  |  |
  491  |  |  |*synchronized (top_collector) {
  492  |  |  ||  // Indicate we only want to look at collectors within the top
  493  |  |  ||  // collector (we're going to loop through our user's collectors).
  494  |  |  ||  top_collector.setCursorElementScope(
  495  |  |  ||            IALibrary.IALibICCS_collectors);
  496  |  |  ||
  497  |  |  ||  // Create the user's collector object
  498  |  |  ||  // Using the parent collector (in this case top)
  499  |  |  ||  // And the name of the collector (pulled from contents element)
  500  |  |  ||  user_collector =
  501  |  |  ||          library.new_IALibInferenceCollector(top_collector, usr);
  502  |  |  ||
  503  |  |  ||  // Contents element object: Place for find to put it's stuff
  504  |  |  ||  IALibInferenceContentsElement contents_element =
  505  |  |  ||                       library.new_IALibInferenceContentsElement();
  506  |  |  ||
  507  |  |  ||  if (top_collector.find(contents_element, usr,
  508  |  |  || *                  IALibrary.IALibICET_collector)) {
  509  |  |  || |
  510  |  |  || |   // User Collector exists. Populate it with data from persistant store
  511  |  |  || |   // If collector metadata exists (user has messages pending),
  512  |  |  || |   // we need to load it into the user_collector so that when it
  513  |  |  || |   // comes time to 'delete' the rules from persistent storage, we
  514  |  |  || |   // can tell if there is metadata or not.
  515  |  |  || |   user_collector.setMetadataName('1');
  516  |  |  || |  *try {
  517  |  |  || |  |  user_collector.get();
  518  |  |  || | **} catch (IAError e) {
  519  |  |  || | |   if (e.msgnumber() !=
  520  |  |  || | |       IAError.IA_E_LIBRARY_COLLECTOR_METADATA_EXISTENCE_ERROR)
  521  |  |  || | |     throw e;           // Other get problem, rethrow...
  522  |  |  || | * }
  523  |  |  || |   newUser = false;
  524  |  |  || |   System.out.println("Collector exists");
  525  |  |  ||**} else {
  526  |  |  |||    if (cmd.equals("GET")) return 2;   // Don't create user for get
  527  |  |  |||   *else {
  528  |  |  |||   |// User Collector does not exist. Create it in persistant storage
  529  |  |  |||   |System.out.println("Collector doesn't exist. Create one..");
  530  |  |  |||   |user_collector.put();
  531  |  |  |||   *}
  532  |  |  ||* }
  533  |  |  |*}   // End of synchronized block for top_collector
  534  |  | **} catch (IAError e) {
  535  |  | |    System.out.println("Caught IAError: " + e.errormsg());
  536  |  | |    System.out.println("Could not create user's collector!");
  537  |  | |    return 4; //could not create a user's collector in persistant storage
  538  |  | * }
  539  |  |
  540  |  |   //user has a collector, give user a rule Set
  541  |  |   System.out.println("Collector Name: " +
  542  |  |                                user_collector.extractName());
  543  |  |  *try {
  544  |  |  |
  545  |  |  |   // Indicate we only want to access rule sets in the user's collector.
  546  |  |  |   user_collector.setCursorElementScope(
  547  |  |  |              IALibrary.IALibICCS_rulesets);
  548  |  |  |
  549  |  |  |   // Get empty rule set element object
  550  |  |  |   current_ruleset_element =
  551  |  |  |       library.new_IALibInferenceContentsElement();
  552  |  |  |
  553  |  |  |   // Create rule set object indicating parent collector
  554  |  |  |   // and rule set name
  555  |  |  |
  556  |  |  |   // We create the rule set without a metadata name in order to
  557  |  |  |   // "speed up" any future "put" of the ruleset for the case when the
  558  |  |  |   // rules already exist.
  559  |  |  |   // In the case where the collector doesn't exists, or the
  560  |  |  |   // rule set doesn't exist, then we'll explicitly set the
  561  |  |  |   // metadata name.  This will cause the initial metadata will be put
  562  |  |  |   // into persistent storage on any subsequent user put request.
  563  |  |  |   // Once the metadata is initially placed on persistent storage, we
  564  |  |  |   // don't change it, so there's no need to re-put it and/or get it.
  565  |  |  |
  566  |  |  |   user_ruleset = library.new_IALibInferenceRuleSet(user_collector, usr,
  567  |  |  |                   "", '0' );
  568  |  |  |
  569  |  |  |
  570  |  |  |   // Populate rule set object with data from persistant store
  571  |  |  |  *if (newUser) {
  572  |  |  |  |   user_ruleset.setMetadataName('0');
  573  |  |  |  |   user_ruleset.setMetadata("CONDUCTSET " + usr + "\n" + RemAgent.ruleSetMetadataString);
  574  |  |  |  |   return 2;
  575  |  |  | **} else {
  576  |  |  | |    if (user_collector.find(current_ruleset_element,usr,
  577  |  |  | |                            IALibrary.IALibICET_ruleset))
  578  |  |  | |     *{
  579  |  |  | |     |user_ruleset.get();
  580  |  |  | |     *}
  581  |  |  | |   *else {
  582  |  |  | |   |   // This can happen if the user collector exists for the purpose
  583  |  |  | |   |   // of housing user messages, but the user rules have been
  584  |  |  | |   |   // deleted.
  585  |  |  | |   |   System.out.println("User has an empty ruleSet!");
  586  |  |  | |   |   user_ruleset.setMetadataName('0');
  587  |  |  | |   |   user_ruleset.setMetadata("CONDUCTSET " + usr + "\n" + RemAgent.ruleSetMetadataString);
  588  |  |  | |   |   return 2;
  589  |  |  | |   *}
  590  |  |  | * }
  591  |  | **} catch (IAError e) {
  592  |  | |
  593  |  | |    // Could not give user a new rule set
  594  |  | |    System.out.println("Caught IAError: " + e.errormsg());
  595  |  | |    System.out.println("No ruleSet in persistant storage!");
  596  |  | |    return 3; //new collector for user but no ruleset in persistant storage
  597  |  | * }
  598  |  |   return 0;
  599  |  *}  //end setupRulesAccess
  600  |
  601  |   // *************************************************************************
  602  |  *boolean saveReminderInLibrary(String remID, String remStr, boolean newFlg) {
  603  |  |
  604  |  |   Reminder rem = new Reminder(remStr);
  605  |  |
  606  |  |   // Put the specific rule in the Library; // ruleStr is in KIFF format
  607  |  |  *try {
  608  |  |  |   System.out.println("Create the rule..");
  609  |  |  |
  610  |  |  |   // rule_name, rule_id, KIFF_string, metadata
  611  |  |  |   user_rule = library.new_IALibInferenceRule(
  612  |  |  |                                remID + "Set1", remID + "Set1",
  613  |  |  |                                rem.getAlarmSet1Rule(), remStr);
  614  |  |  |   user_ruleset.addRule(user_rule);
  615  |  |  |
  616  |  |  |   user_rule = library.new_IALibInferenceRule(
  617  |  |  |                                remID + "Set2", remID + "Set2",
  618  |  |  |                                rem.getAlarmSet2Rule(), "");
  619  |  |  |   user_ruleset.addRule(user_rule);
  620  |  |  |
  621  |  |  |   user_rule = library.new_IALibInferenceRule(
  622  |  |  |                                remID + "Set3", remID + "Set3",
  623  |  |  |                                rem.getAlarmSet3Rule(), "");
  624  |  |  |   user_ruleset.addRule(user_rule);
  625  |  |  |
  626  |  |  |   user_rule = library.new_IALibInferenceRule(
  627  |  |  |                                remID + "Pop", remID + "Pop",
  628  |  |  |                                rem.getAlarmPopRule(), "");
  629  |  |  |   user_ruleset.addRule(user_rule);
  630  |  |  |
  631  |  |  |   // save the rule
  632  |  |  |   System.out.println("Save the rules..");
  633  |  |  |   user_ruleset.put();
  634  |  |  |   String csname = File.separator + userID + File.separator + userID;
  635  |  |  |   System.out.println("Conduct Set Name= " + csname);
  636  |  |  |  *if (newFlg) {
  637  |  |  |  |   RemAgent.theAgent.loadConductSet(RemAgent.libHandle,
  638  |  |  |  |                               RemAgent.engineHandle, csname, userID);
  639  |  |  |  *   }
  640  |  |  |  *else {
  641  |  |  |  |   RemAgent.theAgent.reset(userID);
  642  |  |  |  |   RemAgent.theAgent.loadConductSet(RemAgent.libHandle,
  643  |  |  |  |                               RemAgent.engineHandle, csname, userID);
  644  |  |  |  *   }
  645  |  | **} catch (IAError e) {
  646  |  | |          System.out.println("Add New Rule- Caught IAError: " + e.errormsg());
  647  |  | |          return false;
  648  |  | * }
  649  |  |   return true;
  650  |  *} //end saveReminderInLibrary()
  651  |
  652  |   // ************************************************************************
  653  |  *boolean deleteReminderFromLibrary(String remID) {
  654  |  |
  655  |  |   //remove an existing rule; 1st. find the first rule
  656  |  |  *try {
  657  |  |  |   user_rule = library.new_IALibInferenceRule(remID + "Set1");
  658  |  |  |  *if (user_ruleset.find(remID + "Set1", user_rule)) {
  659  |  |  |  |
  660  |  |  |  |   // delete the rule
  661  |  |  |  |   System.out.println("Delete the rule..");
  662  |  |  |  |   user_ruleset.deleteRule();
  663  |  |  | **} else {
  664  |  |  | |    System.out.println("Removing existing reminder: Rule can not be found!.");
  665  |  |  | |    return false;
  666  |  |  | * }
  667  |  |  |   //remove an existing rule; 1st. find the second rule              @bb
  668  |  |  |   user_rule = library.new_IALibInferenceRule(remID + "Set2");
  669  |  |  |  *if (user_ruleset.find(remID + "Set2", user_rule)) {
  670  |  |  |  |
  671  |  |  |  |   // delete the rule
  672  |  |  |  |   System.out.println("Delete the rule..");
  673  |  |  |  |   user_ruleset.deleteRule();
  674  |  |  | **} else {
  675  |  |  | |    System.out.println("Removing existing reminder: Rule can not be found!.");
  676  |  |  | |    return false;
  677  |  |  | * }
  678  |  |  |   //remove an existing rule; 1st. find the third rule               @bb
  679  |  |  |   user_rule = library.new_IALibInferenceRule(remID + "Set3");
  680  |  |  |  *if (user_ruleset.find(remID + "Set3", user_rule)) {
  681  |  |  |  |
  682  |  |  |  |   // delete the rule
  683  |  |  |  |   System.out.println("Delete the rule..");
  684  |  |  |  |   user_ruleset.deleteRule();
  685  |  |  | **} else {
  686  |  |  | |    System.out.println("Removing existing reminder: Rule can not be found!.");
  687  |  |  | |    return false;
  688  |  |  | * }
  689  |  |  |  *if (user_ruleset.find(remID + "Pop", user_rule)) {
  690  |  |  |  |
  691  |  |  |  |   // delete the rule
  692  |  |  |  |   System.out.println("Delete the rule..");
  693  |  |  |  |   user_ruleset.deleteRule();
  694  |  |  | **} else {
  695  |  |  | |    System.out.println("Removing existing reminder: Rule can not be found!.");
  696  |  |  | |    return false;
  697  |  |  | * }
  698  |  | **} catch (IAError e) {
  699  |  | |    System.out.println("Remove Rule- Caught IAError: " + e.errormsg());
  700  |  | |    return false;
  701  |  | * }
  702  |  |   return true;
  703  |  *} //end deleteReminderFromLibrary
  704  |   // ************************************************************************
  705  |
  706  |   // *************************************************************************
  707  |   // Get user's rules (rule set) from library (persistant storage)
  708  |   // Rules are returned as a tokenized string as indexed reminder strings:
  709  |   // index1Str;rem1Str;index2;rem2Str;..
  710  |  *String getUserRules() {
  711  |  |
  712  |  |   String remsStr = null;
  713  |  |   String ruleNameStr = null;
  714  |  |   int    ruleNameLen = 0;
  715  |  |  *try {
  716  |  |  |
  717  |  |  |   // Get number of rules in rule set
  718  |  |  |   number_of_rules = user_ruleset.size();
  719  |  |  |   System.out.println("Rule Set Name: " + user_ruleset.extractName()
  720  |  |  |                                    + " # of rules= " + number_of_rules);
  721  |  |  |
  722  |  |  |   if ( 0 == number_of_rules ) return null;
  723  |  |  |
  724  |  |  |   // Get first rule
  725  |  |  |   user_rule = user_ruleset.firstRule();
  726  |  |  |   ruleNameStr = user_rule.extractName();
  727  |  |  |   ruleNameLen = ruleNameStr.length();
  728  |  |  |
  729  |  |  |   // Don't need to convert rules to reminders since the reminder
  730  |  |  |   // string is already stored in the meta data of the rule..
  731  |  |  |  *if (ruleNameLen >= 4){
  732  |  |  |  | *if (ruleNameStr.substring(ruleNameLen-4).compareTo("Set1") == 0) {
  733  |  |  |  | |  remsStr = user_rule.extractMetadata() + ";";
  734  |  |  |  | *}
  735  |  |  |  *}
  736  |  |  |
  737  |  |  |   // Loop through the rule set for each rule..
  738  |  |  |   // Concatinate in remsStr the rule-level metadata that is associated with each
  739  |  |  |   // of the "......Set1" named rules (metadata is only stored once - with the first
  740  |  |  |   // rule of a set of rules that represent each reminder.
  741  |  |  |
  742  |  |  |  *for (int i = 1; i < number_of_rules; i++) {
  743  |  |  |  |
  744  |  |  |  |    // Get next rule
  745  |  |  |  |    user_rule = user_ruleset.nextRule();
  746  |  |  |  |    ruleNameStr = user_rule.extractName();
  747  |  |  |  |    ruleNameLen = ruleNameStr.length();
  748  |  |  |  |
  749  |  |  |  |   *if (ruleNameLen >= 4){
  750  |  |  |  |   | *if (ruleNameStr.substring(ruleNameLen-4).compareTo("Set1") == 0) {
  751  |  |  |  |   | |  remsStr = remsStr + user_rule.extractMetadata() + ";";
  752  |  |  |  |   | *}
  753  |  |  |  |   *}
  754  |  |  |  *}
  755  |  | **} catch (IAError e) {
  756  |  | |    System.out.println("Caught IAError: " + e.errormsg());
  757  |  | |    remsStr = null;
  758  |  | * }
  759  |  |   System.out.println("remsStr=  " + remsStr);
  760  |  |   return remsStr;
  761  |  *} // end getUserRules()
  762  |
  763  |   //Create unique Reminder ID from time & date
  764  |  *String createUniqueID() {
  765  |  |   Date d = new Date();
  766  |  |   return (new Integer(d.hashCode())).toString();
  767  |  |
  768  |  *}
  769  |
  770  |
  771  |   //-------------------------------------------------------------------------
  772  |   // Method: getMsgs( String )
  773  |   //-------------------------------------------------------------------------
  774  |  *public String getMsgs( String aUser, boolean mark ) {
  775  |  |  if ( debug ) System.out.println( "Connection::getMsgs - Start --->" );
  776  |  |
  777  |  |  String answer;
  778  |  |  boolean retry;
  779  |  |  int rc = 0;
  780  |  |  int retryCount = 0;
  781  |  |
  782  |  | *do {
  783  |  | |  retry = false;
  784  |  | |  if ( getUserMessages( aUser ) )
  785  |  | |   *{
  786  |  | |   |answer = msgCollection.print();
  787  |  | |   *if ( mark ) {
  788  |  | |   |  msgCollection.markAllRead();
  789  |  | |   | *if ( (rc = updateUserMsgs( aUser )) == 1 ) {
  790  |  | |   | |  retry = true;                // version conflict - retry
  791  |  | |   | |  retryCount++;
  792  |  | |   | *  }
  793  |  | |   *  }
  794  |  | |   *}
  795  |  | |  else                             // user has no messages!!
  796  |  | |    answer = "500 ";
  797  |  | *} while (retry && (retryCount <= 2));
  798  |  |
  799  |  | *if (rc > 0) {
  800  |  | |  answer = "501 ";                 // error writing messages back to file
  801  |  | *  }
  802  |  |
  803  |  |  if ( debug ) System.out.println( "Connection::getMsgs - End   <---" );
  804  |  |  return( answer );
  805  |  *}
  806  |
  807  |   //-------------------------------------------------------------------------
  808  |   // Method: deleteMsgs( String, String )
  809  |   //-------------------------------------------------------------------------
  810  | * public String deleteMsgs( String aUser, String msgsToDelete ) {
  811  | |   if ( debug ) System.out.println( "Connection::deleteMsgs - Start --->" );
  812  | |
  813  | |   boolean retry;
  814  | |   int rc = 0;
  815  | |   int retryCount = 0;
  816  | |
  817  | |   String  answer, aLine = new String(), aMsgID;
  818  | |   int i;
  819  | |
  820  | |  *do {
  821  | |  |  retry = false;
  822  | |  |  if ( getUserMessages( aUser ) )
  823  | |  |   *{
  824  | |  |   |StringTokenizer sT = new StringTokenizer( msgsToDelete, "," );
  825  | |  |   |while ( sT.hasMoreTokens() )
  826  | |  |   | *{
  827  | |  |   | |aMsgID = sT.nextToken();
  828  | |  |   | |for ( i = 0; i < msgCollection.size(); i++)
  829  | |  |   | | *{
  830  | |  |   | | |if ( ((RemMessage)msgCollection.elementAt( i )).msgID().equals( aMsgID ) )
  831  | |  |   | | | *{
  832  | |  |   | | | |if (debug)
  833  | |  |   | | | |   System.out.println( "Connection::deleteMsgs - going to delete "
  834  | |  |   | | | |                  + "message with ID = " + aMsgID);
  835  | |  |   | | | |msgCollection.removeElementAt( i ) ;
  836  | |  |   | | | |break;
  837  | |  |   | | | *}
  838  | |  |   | | *}
  839  | |  |   | *}
  840  | |  |   | *if ( (rc = updateUserMsgs( aUser )) == 1 ) {
  841  | |  |   | |  retry = true;                // version conflict - retry
  842  | |  |   | |  retryCount++;
  843  | |  |   | *  }
  844  | |  |   *}
  845  | |  |  else
  846  | |  |    answer = "501 " + aUser + " " + msgsToDelete;
  847  | |  *} while (retry && (retryCount <= 2));
  848  | |
  849  | |   if (rc == 0)
  850  | |     answer = "220 ";
  851  | |   else
  852  | |     answer = "500 ";
  853  | |
  854  | |   if ( debug ) System.out.println( "Connection::deleteMsgs - End   <---" );
  855  | |   return( answer );
  856  | *}
  857  |
  858  |   //-------------------------------------------------------------------------
  859  |   // Method: markMsgs( String, String )
  860  |   //-------------------------------------------------------------------------
  861  | * public String markMsgs( String aUser, String msgsToMark ) {
  862  | |   if ( debug ) System.out.println( "Connection::markMsgs - Start --->" );
  863  | |
  864  | |   boolean retry;
  865  | |   int rc = 0;
  866  | |   int retryCount = 0;
  867  | |
  868  | |   String  answer, aLine = new String(), msgID;
  869  | |   int i;
  870  | |
  871  | |  *do {
  872  | |  |  retry = false;
  873  | |  |  if ( getUserMessages( aUser ) )
  874  | |  |   *{
  875  | |  |   |StringTokenizer sT = new StringTokenizer( msgsToMark, "," );
  876  | |  |   |while ( sT.hasMoreTokens() )
  877  | |  |   | *{
  878  | |  |   | |msgID = sT.nextToken() ;
  879  | |  |   | |for ( i = 0; i < msgCollection.size(); i++ )
  880  | |  |   | | *{
  881  | |  |   | | |if ( ((RemMessage)msgCollection.elementAt( i )).msgID().equals( msgID ) )
  882  | |  |   | | | *{
  883  | |  |   | | | |if (debug)
  884  | |  |   | | | |  System.out.println( "Connection::markMsgs - going to mark as new "
  885  | |  |   | | | |                      + msgID );
  886  | |  |   | | | |( (RemMessage)msgCollection.elementAt( i )).setStatus( 'n' ) ;
  887  | |  |   | | | |break;
  888  | |  |   | | | *}
  889  | |  |   | | *}
  890  | |  |   | *}
  891  | |  |   | *if ( (rc = updateUserMsgs( aUser )) == 1 ) {
  892  | |  |   | |  retry = true;                // version conflict - retry
  893  | |  |   | |  retryCount++;
  894  | |  |   | *  }
  895  | |  |   *}
  896  | |  |  else
  897  | |  |    answer = "501 " + aUser + " " + msgsToMark;
  898  | |  *} while (retry && (retryCount <= 2));
  899  | |
  900  | |   if (rc == 0)
  901  | |     answer = "220 ";
  902  | |   else
  903  | |     answer = "500 ";
  904  | |
  905  | |
  906  | |   if ( debug ) System.out.println( "Connection::markMsgs - End   <---" );
  907  | |   return( answer );
  908  | *}
  909  |
  910  |   //-------------------------------------------------------------------------
  911  |   // Method: newMsgs( String )
  912  |   //-------------------------------------------------------------------------
  913  | * public String newMsgs( String aUser ) {
  914  | |   if ( debug ) System.out.println( "Connection::newMsgs - Start --->" );
  915  | |
  916  | |   String  answer;
  917  | |   boolean newMsgs = false;
  918  | |
  919  | |   if ( getUserMessages( aUser ) )
  920  | |    *{
  921  | |    |if ( msgCollection.size() > 0 )
  922  | |    | *{
  923  | |    | | for ( int i = 0; i < msgCollection.size(); i++ )
  924  | |    | | * {
  925  | |    | | | if ( ((RemMessage)msgCollection.elementAt( i )).status( ) == 'n' )
  926  | |    | | |  *{
  927  | |    | | |  |newMsgs = true;
  928  | |    | | |  |break;
  929  | |    | | |  *}
  930  | |    | | *}
  931  | |    | | if ( newMsgs )
  932  | |    | |   answer = "220 ";          // User has new messages
  933  | |    | | else
  934  | |    | |   answer = "500 ";          // User has messages, but none are new
  935  | |    | *}
  936  | |    |else
  937  | |    |  answer = "221 ";
  938  | |    *}
  939  | |   else
  940  | |     answer = "501 ";
  941  | |
  942  | |
  943  | |   if ( debug ) System.out.println( "Connection::newMsgs - End   <---" );
  944  | |   return( answer );
  945  | *}
  946  |
  947  |  //-------------------------------------------------------------------------
  948  |  // Method: getUserMessages( String )  (was createCollection)
  949  |  //-------------------------------------------------------------------------
  950  | *public boolean getUserMessages( String aUser ) {
  951  | |  if ( debug ) System.out.println( "Connection::getUserMessages - Start --->" );
  952  | |
  953  | |  boolean      answer = true;
  954  | |
  955  | |  msgCollection.removeAllElements();
  956  | |
  957  | | *try {
  958  | | |  user_collector = library.new_IALibInferenceCollector(top_collector,aUser);
  959  | | |  user_collector.setMetadataName('1');
  960  | | |  user_collector.get();
  961  | | |
  962  | | |  String                   aLine = new String();
  963  | | |  String                   msgs = new String(user_collector.extractMetadata());
  964  | | |  BufferedReader           dataIn = new BufferedReader(new StringReader( msgs ));
  965  | | |  RemMessage               theMessage;
  966  | | |  while ( true )
  967  | | |   *{
  968  | | |   |aLine = dataIn.readLine();
  969  | | |   |if ( aLine == null )
  970  | | |   |  break;
  971  | | |   |theMessage = new RemMessage( aLine );
  972  | | |   |msgCollection.addElement( theMessage );
  973  | | |   *}
  974  | | *}
  975  | | *catch (IOException e) {
  976  | | |   user_collector = null;
  977  | | |   answer = false;
  978  | | *}
  979  | | *catch (IAError e) {
  980  | | |   answer = false;
  981  | | *}
  982  | |
  983  | |  if ( debug ) System.out.println( "Connection::getUserMessages - End   <---" );
  984  | |  return( answer );
  985  | *}
  986  |
  987  |  //-------------------------------------------------------------------------
  988  |  // Method: updateUserMsgs( String ) (was writeCollection)
  989  |  // Returns:  0  = Message log successfully updated in library
  990  |  //           1  = Update failed, version conflict (msgs changed after they
  991  |  //                were retrieved - must retrieve again and retry)
  992  |  //           2  = Update failed, notify user
  993  |  //-------------------------------------------------------------------------
  994  | *public int updateUserMsgs( String aUser ) {
  995  | |  if ( debug ) System.out.println( "Connection::updateUserMsgs - Start --->" );
  996  | |
  997  | |  int      answer = 0;
  998  | |
  999  | | *if (user_collector != null) { // The new was successful during creation...
 1000  | | | *if (!msgCollection.isEmpty()) {   // If msgs remain, update pers stor
 1001  | | | |  try
 1002  | | | |   *{
 1003  | | | |   |  user_collector.setMetadata( msgCollection.print() );
 1004  | | | |   | *synchronized (top_collector) {
 1005  | | | |   | |  user_collector.put();
 1006  | | | |   | *  }
 1007  | | | |   *}
 1008  | | | |  catch( IAError e)
 1009  | | | |   *{
 1010  | | | |   |if (e.msgnumber() == IAError.IA_E_LIBRARY_VERSION_ERROR)
 1011  | | | |   |   answer = 1;
 1012  | | | |   |else
 1013  | | | |   |   answer = 2;
 1014  | | | |   *}
 1015  | | |**  } else {                          // No msgs left, clean up pers stor
 1016  | | ||     *try {
 1017  | | ||     |  IALibInferenceContentsElement element =
 1018  | | ||     |      library.new_IALibInferenceContentsElement();
 1019  | | ||     |  user_collector.setCursorElementScope(IALibrary.IALibICCS_rulesets);
 1020  | | ||     |  if (user_collector.find(element,user_collector.extractName(),
 1021  | | ||     | *                        IALibrary.IALibICET_ruleset))  {
 1022  | | ||     | |    // No messages, but reminders exist. Delete persistent msgs
 1023  | | ||     | |    user_collector.delMetadata('1');
 1024  | | ||     |**} else {
 1025  | | ||     ||     // No messages, no reminders, delete user collector.
 1026  | | ||     ||    *synchronized (top_collector) {
 1027  | | ||     ||    |  user_collector.del();
 1028  | | ||     ||    *  }
 1029  | | ||     |* }
 1030  | | ||    **} catch (IAError e) {
 1031  | | ||    |   answer = 2;                  // Update failed, notify user
 1032  | | ||    * }
 1033  | | |*   }                                 // End of no msgs left
 1034  | | *  }
 1035  | | *else {              // Collector creation failed, nothing to update
 1036  | | |  answer = 2;
 1037  | | *  }
 1038  | |
 1039  | |  if ( debug ) System.out.println( "Connection::updateUserMsgs - End   <---" );
 1040  | |  return( answer );
 1041  | *}
 1042  |
 1043  |/*****************************************************************************
 1044  | *  End of methods pulled from the MsgCollection class.
 1045  | *****************************************************************************
 1046  | */
 1047  |
 1048  | *private String convertNLs( String aline ) {
 1049  | |  String workline = "";
 1050  | |  int startIndex = 0;
 1051  | |  int index;
 1052  | |
 1053  | | *while ((index = aline.indexOf('\\',startIndex)) != -1) {  // While escapes
 1054  | | |  *if (aline.charAt(index+1) == 'n') {                    // If \\n
 1055  | | |  |  workline += aline.substring(startIndex, index);      // Get up to \\n
 1056  | | |  |  workline += "\n";                                    // Add \n
 1057  | | |  *}
 1058  | | |   startIndex = index+2;                                  // Bump past \\n
 1059  | | *}
 1060  | |  if (workline == "")                                       // If no escapes
 1061  | |     workline = aline;                                      // return orig
 1062  | |  else
 1063  | |     workline += aline.substring(startIndex);               // Get remaining
 1064  | |  return workline;                                          // return convrtd
 1065  | *}
 1066  |
 1067  *}  // end of class Connection


Reminder Class

 
    1   // Reminder class
    2  *class Reminder {
    3  |   String NL;
    4  |   String remStr;
    5  |   String remMsg;
    6  |   String idStr;
    7  |   String idStr2;
    8  |   String typeStr;
    9  |   String nameStr;
   10  |   String monthStr;
   11  |   String dayStr;
   12  |   String yearStr;
   13  |   String dateStr;
   14  |   String countStr;
   15  |   String countStr1;
   16  |   int icount;
   17  |   String viaStr;
   18  |   String userIDStr;
   19  |   String userEmailStr;
   20  |   String timeStr = "10:00:00";
   21  |
   22  |  *Reminder(String rem) {
   23  |  |   remStr = rem;
   24  |  |   StringTokenizer st = new StringTokenizer(rem, "#=");
   25  |  |   String attr, val;
   26  |  |  *try {
   27  |  |  |   attr = st.nextToken();
   28  |  |  |   val  = st.nextToken();
   29  |  |  |   idStr = val;
   30  |  |  |   idStr2 = idStr + "Y";
   31  |  |  |   System.out.println(attr + "\t" + val);
   32  |  |  |   attr = st.nextToken();
   33  |  |  |   val  = st.nextToken();
   34  |  |  |   typeStr = val;
   35  |  |  |   System.out.println(attr + "\t" + val);
   36  |  |  |   attr = st.nextToken();
   37  |  |  |   val  = st.nextToken();
   38  |  |  |   nameStr = val;
   39  |  |  |   System.out.println(attr + "\t" + val);
   40  |  |  |   attr = st.nextToken();
   41  |  |  |   val  = st.nextToken();
   42  |  |  |   monthStr = val;
   43  |  |  |   System.out.println(attr + "\t" + val);
   44  |  |  |   attr = st.nextToken();
   45  |  |  |   val  = st.nextToken();
   46  |  |  |   dayStr = val;
   47  |  |  |   if (1 == dayStr.length()) dayStr = "0" + dayStr;
   48  |  |  |   System.out.println(attr + "\t" + val);
   49  |  |  |   attr = st.nextToken();
   50  |  |  |   val  = st.nextToken();
   51  |  |  |   yearStr = val;
   52  |  |  |   dateStr = yearStr + "-" + monthToNum(monthStr) + "-" + dayStr;
   53  |  |  |   System.out.println(attr + "\t" + val);
   54  |  |  |   attr = st.nextToken();
   55  |  |  |   val  = st.nextToken();
   56  |  |  |   countStr = val;
   57  |  |  |   // Following is to bump the value in countStr by 1 because we start
   58  |  |  |   // alarms (from the rules) on the day before the lead time given by
   59  |  |  |   // the client (alarm does not go off until the following day).
   60  |  |  |   icount = Integer.parseInt(countStr);
   61  |  |  |   icount++;
   62  |  |  |   countStr1 = new String(Integer.toString(icount));
   63  |  |  |   System.out.println(attr + "\t" + val);
   64  |  |  |   attr = st.nextToken();
   65  |  |  |   val  = st.nextToken();
   66  |  |  |   viaStr = val;
   67  |  |  |   if (viaStr.equals("E-Mail")) NL = "\\n";  // \n to e-mail
   68  |  |  |   else NL = "\\\\n";                        // \\n to msg adapter
   69  |  |  |   System.out.println(attr + "\t" + val);
   70  |  |  |   attr = st.nextToken();
   71  |  |  |   val  = st.nextToken();
   72  |  |  |   userIDStr = val;
   73  |  |  |   System.out.println(attr + "\t" + val);
   74  |  |  |   attr = st.nextToken();
   75  |  |  |   val  = st.nextToken();
   76  |  |  |   userEmailStr = val;
   77  |  |  |   System.out.println(attr + "\t" + val);
   78  |  | **} catch(NoSuchElementException e) {
   79  |  | |    System.out.println("Server: error decoding reminder String: " + e);
   80  |  | * }
   81  |  |   Date d = new Date();
   82  |  |
   83  |  |   if ( d.getHours() < 10 )
   84  |  |     timeStr = "0";
   85  |  |   timeStr += (new Integer(d.getHours()).toString()) + ":";
   86  |  |
   87  |  |   if ( d.getMinutes() < 10 )
   88  |  |     timeStr += "0";
   89  |  |   timeStr += (new Integer(d.getMinutes()).toString()) + ":";
   90  |  |
   91  |  |   if ( d.getSeconds() < 10 )
   92  |  |     timeStr += "0";
   93  |  |   timeStr += (new Integer(d.getSeconds()).toString() );
   94  |  |
   95  |  |   remMsg = createReminderMessage();
   96  |  *}
   97  |
   98  |   // Create message to be sent to the user for this reminder.
   99  |  *String createReminderMessage() {
  100  |  |   String msgStr;
  101  |  |   if ( viaStr.equals("E-Mail") )
  102  |  |     *{
  103  |  |     |msgStr = "Hello " + userIDStr + ": " + NL + NL +
  104  |  |     |   "This is a reminder that on " +
  105  |  |     |   monthStr + " " + dayStr + NL +
  106  |  |     |   "you have the following " + typeStr +
  107  |  |     |   " event planned: " + NL + nameStr;
  108  |  |     *}
  109  |  |   else
  110  |  |     *{
  111  |  |     |msgStr = "On " + monthStr + " " + dayStr +
  112  |  |     |         " you have the following " + typeStr +
  113  |  |     |         " event planned:<BR>" + nameStr;
  114  |  |     *}
  115  |  |   return msgStr;  //temporarily until ABE fixes new-line in rule
  116  |  *}
  117  |
  118  |   // Create the first setAlarm rule and return a rule string
  119  |
  120  |  *String getAlarmSet1Rule() {
  121  |  |   String ruleStr =
  122  |  |      "(=> (AND (OR (EventName \"AGENT:STARTING\") " +
  123  |  |                   "(EventName \"AGENT:CSCHANGE\")) " +
  124  |  |               "(addTimeInterval " + "\"" + dateStr + "\" " +
  125  |  |                     "\"" + "00:00:01" + "\"" + " -" +
  126  |  |                     countStr1 + " \"days\" ?date ?time))"  +
  127  |  |               "(setRandomStartBoundedIntervalAlarm " +
  128  |  |                  "1 \"years\" ?date ?time 21600 " +
  129  |  |                  "\"" + idStr2 + "\"" + " \"\" ))";
  130  |  |   return ruleStr;
  131  |  *}
  132  |
  133  |   // Create the second setAlarm rule and return a rule string
  134  |
  135  |  *String getAlarmSet2Rule() {
  136  |  |   String ruleStr =
  137  |  |      "(=> (AND (AND (OR (EventName \"AGENT:STARTING\") " +
  138  |  |               "(EventName \"AGENT:CSCHANGE\")) " +
  139  |  |               "(addTimeInterval " + "\"" + dateStr + "\" " +
  140  |  |                     "\"" + "00:00:01" + "\"" + " -" +
  141  |  |                     countStr1 + " \"days\" ?date ?time)) "  +
  142  |  |               "(currentTimeBetween ?date \"00:00:01\" " +
  143  |  |                     "\"" + dateStr + "\" " + "\"06:00:00\")) " +
  144  |  |               "(setRandomBoundedIntervalAlarm 1 \"days\" " +
  145  |  |                     "?date \"00:00:01\" " +
  146  |  |                     "\"" + dateStr + "\" \"06:10:00\" 21600 " +
  147  |  |                     "\"" + idStr + "\"" + " \"\" ))";
  148  |  |   return ruleStr;
  149  |  *}
  150  |
  151  |   // Create the third setAlarm rule and return a rule string
  152  |
  153  |  *String getAlarmSet3Rule() {
  154  |  |   String ruleStr =
  155  |  |      "(=> (AND (AND (AND (EventName \"Time:Alarm\") " +
  156  |  |               "(AlarmId " + "\"" + idStr2 + "\"" + ")) " +
  157  |  |               "(EventTime ?d ?t)) " +
  158  |  |               "(addTimeInterval ?d ?t " + countStr1 + " \"days\" " +
  159  |  |                     "?newdate ?newtime)) " +
  160  |  |               "(setEndBoundedIntervalAlarm " +
  161  |  |                     "1 \"days\" ?newdate ?newtime " +
  162  |  |                     "\"" + idStr + "\"" +  " \"\" ))";
  163  |  |   return ruleStr;
  164  |  *}
  165  |
  166  |
  167  |   // Create and return a rule string
  168  |  *String getAlarmPopRule() {
  169  |  |   String ruleStr;
  170  |  |  *if (viaStr.equals("E-Mail")) {
  171  |  |  |   ruleStr = "(=> (AND (EventName \"Time:Alarm\") " +
  172  |  |  |     "(AlarmId " + "\"" + idStr + "\"" + "))" +
  173  |  |  |     "(EMailWithSubject " + "\"" + userEmailStr + "\"" + " " +
  174  |  |  |     "\"" + remMsg + "\"" + " " + "\"" + nameStr + "\"" + "))";
  175  |  | **} else {
  176  |  | |    ruleStr = "(=> (AND (EventName \"Time:Alarm\") " +
  177  |  | |        "(AlarmId " + "\"" + idStr + "\"" + ")) " +
  178  |  | |        "(SetMessage " + "\"" + remMsg + "\"))";
  179  |  | * }
  180  |  |   return ruleStr;
  181  |  *}
  182  |
  183  |
  184  |   // Convert month string ("January - "December") to Numeric string
  185  |  *String monthToNum(String m) {
  186  |  |   if (m.equals("January")) return "01";
  187  |  |   else if (m.equals("February")) return "02";
  188  |  |   else if (m.equals("March")) return "03";
  189  |  |   else if (m.equals("April")) return "04";
  190  |  |   else if (m.equals("May")) return "05";
  191  |  |   else if (m.equals("June")) return "06";
  192  |  |   else if (m.equals("July")) return "07";
  193  |  |   else if (m.equals("August")) return "08";
  194  |  |   else if (m.equals("September")) return "09";
  195  |  |   else if (m.equals("October")) return "10";
  196  |  |   else if (m.equals("November")) return "11";
  197  |  |   else if (m.equals("December")) return "12";
  198  |  |   else return null;
  199  |  *}
  200  |
  201  |   // Convert year string "1996" to abbreveated year "96" string
  202  |  *String shortYear(String y) {
  203  |  |   if (4 <= y.length()) return y.substring(2);
  204  |  |   if (3 == y.length()) return y.substring(1);
  205  |  |   return y;
  206  |  *}
  207  |
  208  *} //end Reminder class


RemMessage Class

 
    1   /*************************************************************************
    2   ** File:         Message.java
    3   ** Description:  Reminder Message Class used by RemAgent - sample agent for reminders
    4   **
    5   ** DISCLAIMER OF WARRANTIES:
    6   ** -------------------------
    7   ** The following [enclosed] code is sample code created by IBM
    8   ** Corporation.  This sample code is not part of any standard IBM product
    9   ** and is provided to you solely for the purpose of assisting you in the
   10   ** development of your applications.  The code is provided "AS IS",
   11   ** without warranty of any kind.  IBM shall not be liable for any damages
   12   ** arising out of your use of the sample code, even if they have been
   13   ** advised of the possibility of such damages.
   14   *************************************************************************/
   15
   16   // Description: The Reminder Message Class
   17   //
   18   //-----------------------------------------------------------------------------
   19   import java.util.Date;
   20
   21   public class RemMessage
   22  *{
   23  |    //-------------------------------------------------------------------------
   24  |    // Instance variables
   25  |    //-------------------------------------------------------------------------
   26  |  private char    theStatus;         // Status of the message
   27  |  private String  theID;             // Unique ID of the message
   28  |  private String  theDate;           // The date the message was created
   29  |  private String  theTime;           // The time the message was created
   30  |  private String  theTimeZone;       // The time zone the message was created
   31  |  private String  theMessage;        // The message!
   32  |  private boolean debug = false;     // Debug variable
   33  |
   34  |    //-------------------------------------------------------------------------
   35  |    // Constructor  (default)
   36  |    //-------------------------------------------------------------------------
   37  |  public RemMessage( )
   38  |   *{
   39  |   |
   40  |   *}
   41  |
   42  |    //-------------------------------------------------------------------------
   43  |    // Constructor from aLine
   44  |    //
   45  |    // Description: Does no error checking, assumes line was created by print()
   46  |    //-------------------------------------------------------------------------
   47  |  public RemMessage( String aLine )
   48  |   *{
   49  |   |char status;
   50  |   |String    msgID, date, time, timeZone, message, blank = " ";
   51  |   |
   52  |   |int start= 2;
   53  |   |int end = 0;
   54  |   |if ( debug )
   55  |   |  System.out.println( "    The line is      : " + aLine );
   56  |   |
   57  |   |status = aLine.charAt( end );
   58  |   |
   59  |   |end  = aLine.indexOf( blank, start );
   60  |   |msgID = aLine.substring( start, end);
   61  |   |
   62  |   |start = ++end;
   63  |   |end  = aLine.indexOf( blank, start );
   64  |   |date = aLine.substring( start, end );
   65  |   |
   66  |   |start = ++end;
   67  |   |end  = aLine.indexOf( blank, start );
   68  |   |time = aLine.substring( start, end );
   69  |   |
   70  |   |start = ++end;
   71  |   |end  = aLine.indexOf( blank, start );
   72  |   |timeZone = aLine.substring( start, end );
   73  |   |
   74  |   |start = ++end;
   75  |   |message = aLine.substring( start );
   76  |   |
   77  |   |if ( debug )
   78  |   | *{
   79  |   | |System.out.println( "    The line is      : " + aLine );
   80  |   | |System.out.println( "    The status is    : " + status );
   81  |   | |System.out.println( "    The ID is        : " + msgID );
   82  |   | |System.out.println( "    The date is      : " + date );
   83  |   | |System.out.println( "    The time is      : " + time );
   84  |   | |System.out.println( "    The time zone is : " + timeZone );
   85  |   | |System.out.println( "    The message is   : " + message );
   86  |   | *}
   87  |   |
   88  |   |theStatus   = status;
   89  |   |theID       = new String( msgID );
   90  |   |theDate     = new String( date );
   91  |   |theTime     = new String( time );
   92  |   |theTimeZone = new String( timeZone );
   93  |   |theMessage  = new String( message );
   94  |   |
   95  |   *}
   96  |
   97  |    //-------------------------------------------------------------------------
   98  |    // Method: print()
   99  |    //-------------------------------------------------------------------------
  100  |  public String print( )
  101  |   *{
  102  |   |String aString = new String( theStatus   + " " +
  103  |   |                             theID       + " " +
  104  |   |                             theDate     + " " +
  105  |   |                             theTime     + " " +
  106  |   |                             theTimeZone + " " +
  107  |   |                             theMessage  + "\n" );
  108  |   |return( aString );
  109  |   *}
  110  |
  111  |    //-------------------------------------------------------------------------
  112  |    // Method: setStatus( char )
  113  |    //-------------------------------------------------------------------------
  114  |  public void setStatus( char aStatus )
  115  |   *{
  116  |   |if ( aStatus == 'n' )
  117  |   |  theStatus  = aStatus;
  118  |   |else
  119  |   |  theStatus = 'o';
  120  |   *}
  121  |
  122  |    //-------------------------------------------------------------------------
  123  |    // Method: status( )
  124  |    //-----------------------------------------------------------------------
  125  |  public char status( )
  126  |   *{
  127  |   |return( theStatus );
  128  |   *}
  129  |
  130  |    //-------------------------------------------------------------------------
  131  |    // Method: msgID( ) - return the message ID
  132  |    //-------------------------------------------------------------------------
  133  |  public String msgID( )
  134  |   *{
  135  |   |return( theID );
  136  |   *}
  137  |
  138  |    //-------------------------------------------------------------------------
  139  |    // Method: markRead()
  140  |    //-------------------------------------------------------------------------
  141  |  public void markRead( )
  142  |   *{
  143  |   |theStatus = 'o';
  144  |   *}
  145  |
  146  |    //-------------------------------------------------------------------------
  147  |    // Method: setDate()
  148  |    //-------------------------------------------------------------------------
  149  |  public void setDate( )
  150  |   *{
  151  |   |Date today = new Date();
  152  |   |String month, day;
  153  |   |Integer year;
  154  |   |
  155  |   |month = monthToString( today.getMonth() );
  156  |   |day   = dayToString( today.getDate() );
  157  |   |year  = new Integer( today.getYear() + 1900 );
  158  |   |
  159  |   |theDate = month + "/" + day + "/" + year.toString();
  160  |   |theTime = hourToString( today.getHours() ) + ":" +
  161  |   |          minuteToString( today.getMinutes() );
  162  |   |theTimeZone = "EDT";
  163  |   |
  164  |   *}
  165  |
  166  |    //-------------------------------------------------------------------------
  167  |    // Method: monthToString()
  168  |    // Convert month (int 0-11) to string ("01 - "12")
  169  |    //-------------------------------------------------------------------------
  170  | *String monthToString(int m) {
  171  | | *switch (m) {
  172  | | |  case 0: return "01";
  173  | | |  case 1: return "02";
  174  | | |  case 2: return "03";
  175  | | |  case 3: return "04";
  176  | | |  case 4: return "05";
  177  | | |  case 5: return "06";
  178  | | |  case 6: return "07";
  179  | | |  case 7: return "08";
  180  | | |  case 8: return "09";
  181  | | |  case 9: return "10";
  182  | | |  case 10: return "11";
  183  | | |  case 11: return "12";
  184  | | |  default: return "01";
  185  | | *  }
  186  | * }
  187  |
  188  |    //-------------------------------------------------------------------------
  189  |    // Method: dayToString()
  190  |    // Convert day (int 0-31) to string ("01" - "31")
  191  |    //-------------------------------------------------------------------------
  192  | *String dayToString(int m) {
  193  | | *switch (m) {
  194  | | |  case 1: return "01";
  195  | | |  case 2: return "02";
  196  | | |  case 3: return "03";
  197  | | |  case 4: return "04";
  198  | | |  case 5: return "05";
  199  | | |  case 6: return "06";
  200  | | |  case 7: return "07";
  201  | | |  case 8: return "08";
  202  | | |  case 9: return "09";
  203  | | |  case 10: return "10";
  204  | | |  case 11: return "11";
  205  | | |  case 12: return "12";
  206  | | |  case 13: return "13";
  207  | | |  case 14: return "14";
  208  | | |  case 15: return "15";
  209  | | |  case 16: return "16";
  210  | | |  case 17: return "17";
  211  | | |  case 18: return "18";
  212  | | |  case 19: return "19";
  213  | | |  case 20: return "20";
  214  | | |  case 21: return "21";
  215  | | |  case 22: return "22";
  216  | | |  case 23: return "23";
  217  | | |  case 24: return "24";
  218  | | |  case 25: return "25";
  219  | | |  case 26: return "26";
  220  | | |  case 27: return "27";
  221  | | |  case 28: return "28";
  222  | | |  case 29: return "29";
  223  | | |  case 30: return "30";
  224  | | |  case 31: return "31";
  225  | | |  default: return "01";
  226  | | *  }
  227  | * }
  228  |
  229  |    //-------------------------------------------------------------------------
  230  |    // Method: hourToString()
  231  |    // Convert day (int 0-31) to string ("01" - "31")
  232  |    //-------------------------------------------------------------------------
  233  | *String hourToString(int m) {
  234  | | *switch (m) {
  235  | | |  case 0: return "00";
  236  | | |  case 1: return "01";
  237  | | |  case 2: return "02";
  238  | | |  case 3: return "03";
  239  | | |  case 4: return "04";
  240  | | |  case 5: return "05";
  241  | | |  case 6: return "06";
  242  | | |  case 7: return "07";
  243  | | |  case 8: return "08";
  244  | | |  case 9: return "09";
  245  | | |  case 10: return "10";
  246  | | |  case 11: return "11";
  247  | | |  case 12: return "12";
  248  | | |  case 13: return "13";
  249  | | |  case 14: return "14";
  250  | | |  case 15: return "15";
  251  | | |  case 16: return "16";
  252  | | |  case 17: return "17";
  253  | | |  case 18: return "18";
  254  | | |  case 19: return "19";
  255  | | |  case 20: return "20";
  256  | | |  case 21: return "21";
  257  | | |  case 22: return "22";
  258  | | |  case 23: return "23";
  259  | | |  default: return "00";
  260  | | *  }
  261  | * }
  262  |
  263  |    //-------------------------------------------------------------------------
  264  |    // Method: minuteToString()
  265  |    // Convert day (int 0-31) to string ("01" - "31")
  266  |    //-------------------------------------------------------------------------
  267  | *String minuteToString(int m) {
  268  | | *switch (m) {
  269  | | |  case 0: return "00";
  270  | | |  case 1: return "01";
  271  | | |  case 2: return "02";
  272  | | |  case 3: return "03";
  273  | | |  case 4: return "04";
  274  | | |  case 5: return "05";
  275  | | |  case 6: return "06";
  276  | | |  case 7: return "07";
  277  | | |  case 8: return "08";
  278  | | |  case 9: return "09";
  279  | | |  case 10: return "10";
  280  | | |  case 11: return "11";
  281  | | |  case 12: return "12";
  282  | | |  case 13: return "13";
  283  | | |  case 14: return "14";
  284  | | |  case 15: return "15";
  285  | | |  case 16: return "16";
  286  | | |  case 17: return "17";
  287  | | |  case 18: return "18";
  288  | | |  case 19: return "19";
  289  | | |  case 20: return "20";
  290  | | |  case 21: return "21";
  291  | | |  case 22: return "22";
  292  | | |  case 23: return "23";
  293  | | |  case 24: return "24";
  294  | | |  case 25: return "25";
  295  | | |  case 26: return "26";
  296  | | |  case 27: return "27";
  297  | | |  case 28: return "28";
  298  | | |  case 29: return "29";
  299  | | |  case 30: return "30";
  300  | | |  case 31: return "31";
  301  | | |  case 32: return "32";
  302  | | |  case 33: return "33";
  303  | | |  case 34: return "34";
  304  | | |  case 35: return "35";
  305  | | |  case 36: return "36";
  306  | | |  case 37: return "37";
  307  | | |  case 38: return "38";
  308  | | |  case 39: return "39";
  309  | | |  case 40: return "40";
  310  | | |  case 41: return "41";
  311  | | |  case 42: return "42";
  312  | | |  case 43: return "43";
  313  | | |  case 44: return "44";
  314  | | |  case 45: return "45";
  315  | | |  case 46: return "46";
  316  | | |  case 47: return "47";
  317  | | |  case 48: return "48";
  318  | | |  case 49: return "49";
  319  | | |  case 50: return "50";
  320  | | |  case 51: return "51";
  321  | | |  case 52: return "52";
  322  | | |  case 53: return "53";
  323  | | |  case 54: return "54";
  324  | | |  case 55: return "55";
  325  | | |  case 56: return "56";
  326  | | |  case 57: return "57";
  327  | | |  case 58: return "58";
  328  | | |  case 59: return "59";
  329  | | |  default: return "00";
  330  | | *  }
  331  | * }
  332  |
  333  *}


RemMessageVector Class

 
    1   /*************************************************************************
    2   ** File:         RemMessageVector.java
    3   ** Description:  Reminder Message Vector Class used by sample agent for reminders.
    4   **
    5   ** DISCLAIMER OF WARRANTIES:
    6   ** -------------------------
    7   ** The following [enclosed] code is sample code created by IBM
    8   ** Corporation.  This sample code is not part of any standard IBM product
    9   ** and is provided to you solely for the purpose of assisting you in the
   10   ** development of your applications.  The code is provided "AS IS",
   11   ** without warranty of any kind.  IBM shall not be liable for any damages
   12   ** arising out of your use of the sample code, even if they have been
   13   ** advised of the possibility of such damages.
   14   *************************************************************************/
   15
   16   // Description: This class is a container that holds RemMessage objects
   17   //
   18   //-----------------------------------------------------------------------------
   19   import java.util.Vector;
   20
   21   public class RemMessageVector extends Vector
   22  *{
   23  |    //-------------------------------------------------------------------------
   24  |    // Instance variables
   25  |    //-------------------------------------------------------------------------
   26  |  boolean debug = false;             // Debug variable
   27  |
   28  |    //-------------------------------------------------------------------------
   29  |    // Constructor  (default)
   30  |    //-------------------------------------------------------------------------
   31  |  public RemMessageVector( )
   32  |   *{
   33  |   |
   34  |   *}
   35  |
   36  |    //-------------------------------------------------------------------------
   37  |    // Method: print()
   38  |    //-------------------------------------------------------------------------
   39  |  public String print( )
   40  |   *{
   41  |   |if ( debug ) System.out.println( "RemMessageVector::print() Enter -->" );
   42  |   |String     aString = new String(  );
   43  |   |
   44  |   |for ( int i = 0 ; i < elementCount ; i++ )
   45  |   | *{
   46  |   | |if ( debug ) System.out.println( "RemMessageVector::print() in the loop "
   47  |   | |             + "loop count = " + i );
   48  |   | |aString += ((RemMessage) elementAt(i)).print();
   49  |   | *}
   50  |   |if ( debug ) System.out.println( "RemMessageVector::print() Exit  <--" );
   51  |   |return( aString );
   52  |   *}
   53  |
   54  |
   55  |    //-------------------------------------------------------------------------
   56  |    // Method: markAllRead()
   57  |    //-------------------------------------------------------------------------
   58  |  public void markAllRead( )
   59  |   *{
   60  |   |if ( debug ) System.out.println( "RemMessageVector::markAllRead() Enter -->" );
   61  |   |String     aString = new String(  );
   62  |   |
   63  |   |for ( int i = 0 ; i < elementCount ; i++ )
   64  |   | *{
   65  |   | |if ( debug ) System.out.println( "RemMessageVector::markAllRead() in the loop "
   66  |   | |             + "loop count = " + i );
   67  |   | |((RemMessage) elementAt(i)).markRead();
   68  |   | *}
   69  |   |if ( debug ) System.out.println( "RemMessageVector::markAllRead() Exit  <--" );
   70  |   *}
   71  |
   72  |
   73  *}

Message Adapter Code for Reminder Sample Application


Message Adapter - h file

 
    1   #ifndef MESSAGE_H
    2   #define MESSAGE_H
    3   /*************************************************************************
    4   ** File:         message.h
    5   ** Description:  Header file for a library-based message adapter
    6   **
    7   ** DISCLAIMER OF WARRANTIES:
    8   ** -------------------------
    9   ** The following [enclosed] code is sample code created by IBM
   10   ** Corporation.  This sample code is not part of any standard IBM product
   11   ** and is provided to you solely for the purpose of assisting you in the
   12   ** development of your applications.  The code is provided "AS IS",
   13   ** without warranty of any kind.  IBM shall not be liable for any damages
   14   ** arising out of your use of the sample code, even if they have been
   15   ** advised of the possibility of such damages.
   16   *************************************************************************/
   17
   18   #include <iatk/adapter.h>         // IAAdapter class
   19   #include <i0string.hpp>           // I0String class
   20   #include <iatk/library.h>         // library
   21   #include <iatk/collect.h>         // library
   22
   23   #define SETMESSAGE_TOKEN                                  1
   24
   25   // Note: This adapter generates no events and handles no sensors.  Therefore
   26   // the inherited versions of the following member functions provided
   27   // by the IAAdapter class are adequate for this adapter, and are not
   28   // defined here.  See the doc for adapter creation or the header files
   29   // for the IAAdapter class for information on their function and content.
   30   //     start
   31   //     stop
   32   //     shutdown
   33   //     eventComplete
   34   //     testCondition
   35   //     answerQuery
   36
   37  *class MessageAdapter : public IAAdapter {
   38  | public:
   39  |   MessageAdapter(char * parm);
   40  |   ~MessageAdapter();
   41  |   IABool IACALLBK identify();
   42  |   void IACALLBK performAction(IAProcToken token, const IAEventHeader &hdr,
   43  |      const char *binding);
   44  |
   45  | private:
   46  |
   47  |   IALibrary * myLib;
   48  |
   49  |   IALibInferenceCollector * myCollector;
   50  |
   51  *};  // end of class MessageAdapter
   52   #endif


Message Adapter - cpp file

 






IAAdapter (ABEUGMS2.CPP.A1, page reference #2)
calls
asInt
attachImplementation
getTop
IALibrary
length
libList
numWords
word






identify (ABEUGMS2.CPP.A1, page reference #3)
calls
registerProcedure






MessageAdapter (ABEUGMS2.CPP.A1, page reference #1)
called
by
newAdapter (ABEUGMS2.CPP.A1, page reference #5)






newAdapter (ABEUGMS2.CPP.A1, page reference #5)
calls
MessageAdapter (ABEUGMS2.CPP.A1, page reference #1)
strcmp






performAction (ABEUGMS2.CPP.A1, page reference #4)
calls
asString
catch
delete_IALibInferenceCollector
errormsg
extractMetadata
get
getId
getSelector
getStringTerm
localtime
msgnumber
new_IALibInferenceCollector
put
setKIF
setMetadata
setMetadataName
strftime
theDate
theTime
theZone
time

    1   /*************************************************************************
    2   ** File:         message.cpp
    3   ** Description:  Implementation of a message adapter
    4   **
    5   ** DISCLAIMER OF WARRANTIES:
    6   ** -------------------------
    7   ** The following [enclosed] code is sample code created by IBM
    8   ** Corporation.  This sample code is not part of any standard IBM product
    9   ** and is provided to you solely for the purpose of assisting you in the
   10   ** development of your applications.  The code is provided "AS IS",
   11   ** without warranty of any kind.  IBM shall not be liable for any damages
   12   ** arising out of your use of the sample code, even if they have been
   13   ** advised of the possibility of such damages.
   14   *************************************************************************/
   15   #include <message.h>
   16   #include <iatk/types.h>
   17
   18   #ifdef _AIX
   19      #define IA_AIX
   20      #define IA_UNIX
   21   #endif
   22   #ifdef IA_UNIX
   23   // Character which separates directory names in a file path specification
   24   #define FILEPATH_SEP    "/"
   25   #define FILEPATH_SEPCHR '/'
   26   #else
   27
   28   #define FILEPATH_SEP    "\\"
   29   #define FILEPATH_SEPCHR '\\'
   30   #endif
   31

32 // ---------------------------------------------------------------------- 33 // constructor 34 // ---------------------------------------------------------------------- 35 36 MessageAdapter::MessageAdapter(Ref #1.)(char * parms):IAAdapter(Ref #2.)() 37 *{ 38 | I0String libList(parms); 39 | I0String type=libList.word(1); 40 | I0String dllname=libList.word(2); 41 | I0String map=libList.word(3); 42 | if (map[map.length()-1] != FILEPATH_SEPCHR) 43 | map += FILEPATH_SEP; // Append final path separator 44 | I0String collector=libList.word(4); 45 | int levels; 46 | if (libList.numWords() == 5) // If levels was specified... 47 | levels = (libList.word(5)).asInt(); // 5th arg= # collector levels 48 | else levels = 1; // Otherwise default to 2 levels 49 | myLib=new IALibrary(); 50 | myLib->attachImplementation(map,type,dllname,collector,levels); 51 | myCollector=myLib->getTop(); 52 *} 53

54 MessageAdapter::~MessageAdapter() { delete myLib; }

55 //----------------------------------------------------------------------- 56 // identify - Register our Sensors and Effectors 57 // 58 // Invoke registerProcedure for each Sensor and Effector that we provide, 59 // so that they may be invoked by the inference engine later. If any of 60 // these attempts to register a procedure fails, return a false (zero) 61 // to indicate that our identify() failed; otherwise return true (non-zero). 62 // 63 // registerProcedure is a service method provided by the IAAdapter class 64 // and inherited by SampMailAdapter(); the adapter writer does not have 65 // to provide it. 66 // 67 // To add a new Sensor or Effector to this adapter: 68 // . Add a "<procName>_Token" constant to sampmail.h 69 // . Assign the new "<procName>_Token" a value in sampmail.cpp 70 // . Add a registerProcedure() call to SampMailAdapter::identify() 71 // . Add code to run sensor/effector to SampMailAdapter::answerQuery() or 72 // SampMailAdapter::performAction(), as appropriate 73 //----------------------------------------------------------------------- 74 *IABool MessageAdapter::identify(Ref #3.)() { 75 | 76 | // Register our Sensors 77 | // No sensors to register 78 | 79 | // Register our Effectors 80 | registerProcedure("SetMessage", IAEffectorProc, 81 | "String", SETMESSAGE_TOKEN); 82 | return true; // Success 83 *} 84

85 //----------------------------------------------------------------------- 86 // performAction - Execute Effector procedure 87 // 88 //----------------------------------------------------------------------- 89 void MessageAdapter::performAction(Ref #4.)(IAProcToken token, 90 * const IAEventHeader &hdr, const char *binding) { 91 | 92 | // Build the atom from the binding string 93 | IAAtom atom; 94 | atom.setKIF(binding); 95 | 96 | *if (token == SETMESSAGE_TOKEN) { 97 | | // First build Reminder Message 98 | | time_t temp; 99 | | time(&temp); 100 | | struct tm* timeptr; 101 | | char dest[22]; 102 | | timeptr=localtime(&temp); 103 | | I0String theTime(""); 104 | | I0String theDate(""); 105 | | I0String theZone(""); 106 | | if (timeptr==NULL) cout << "Bad Time" << endl; 107 | | else 108 | | *{ 109 | | | strftime(dest,sizeof(dest)-1,"%m/%d/%EY",timeptr); 110 | | | theDate=dest; 111 | | | strftime(dest,sizeof(dest)-1,"%H:%M",timeptr); 112 | | | theTime=dest; 113 | | | strftime(dest,sizeof(dest)-1,"%Z",timeptr); 114 | | | theZone=dest; 115 | | *} 116 | | I0String messageId=((I0String)(long)temp)+hdr.getId().asString(); 117 | | I0String messageText= atom.getStringTerm(1); 118 | | I0String wholeMessageLine="n "+messageId+" "+theDate+" "+theTime+" "+theZone+" "+messageText+"\n"; 119 | | // new up collector based on selector and set metadataname 120 | | // figure out error handling 121 | | IALibInferenceCollector* currentCollector= 122 | | myLib->new_IALibInferenceCollector(myCollector,hdr.getSelector()); 123 | | currentCollector->setMetadataName('1'); 124 | | // Now do get / put sequence 125 | | IABool recordWritten=false; 126 | | IABool metadataExists=true; 127 | | I0String totalMetadata; 128 | | *while (!recordWritten) { 129 | | | *try { 130 | | | | currentCollector->get(); 131 | | | *} 132 | | | *catch (IAError &e) { 133 | | | | 134 | | | | if (e.msgnumber()==IA_E_LIBRARY_COLLECTOR_METADATA_EXISTENCE_ERROR) 135 | | | | metadataExists=false; 136 | | | | *else { 137 | | | | | cerr << "Error on collector: " << hdr.getSelector() << 138 | | | | | " : " << e.errormsg() << endl; 139 | | | | | myLib->delete_IALibInferenceCollector(currentCollector); 140 | | | | | return; 141 | | | | *} 142 | | | *} 143 | | | if (metadataExists) 144 | | | totalMetadata=currentCollector->extractMetadata()+wholeMessageLine; 145 | | | else totalMetadata=wholeMessageLine; 146 | | | currentCollector->setMetadata(totalMetadata); 147 | | | *try { 148 | | | | currentCollector->put(); 149 | | | | recordWritten=true; 150 | | | *} 151 | | | *catch (IAError &e) { 152 | | | | *if (e.msgnumber()!=IA_E_LIBRARY_VERSION_ERROR) { 153 | | | | | cerr << "Unexpected error on put " << e.errormsg() << endl; 154 | | | | | recordWritten=true; 155 | | | | *} 156 | | | | else cout << "version error" << endl; 157 | | | *} 158 | | *} 159 | | // delete collector 160 | | myLib->delete_IALibInferenceCollector(currentCollector); 161 | *} // end if 162 *} 163

164 //======================================================================= 165 // Global function newAdapter() 166 // 167 // Function newAdapter() is a "factory" function for creating new 168 // instances of SampMail Adapters. 169 // 170 // Input: 171 // *domain = Domain name that identifies the type of concrete 172 // Adapter requested. Only "SampMail" is recognized. 173 // *parms = Adapter start-up parameters obtained from the Agent 174 // configuration file. These are not used by SampMail. 175 // 176 // The adapter instance created by a call to this function is owned by 177 // the IATK framework and should NOT ever be deleted by code in the 178 // adapter module. 179 //======================================================================= 180 *IAAdapter * newAdapter(Ref #5.)(const char *domain, void *parms) { 181 | 182 | *if (strcmp(domain, "Messages")) { 183 | | cerr << "I was called to create an adapter of domain " << domain << 184 | | "only \"Messages\" is valid." << endl; 185 | | return NULL; 186 | *} 187 | 188 | return new MessageAdapter((char *)parms); 189 *}



[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]