// // This file is an example for SXML, a tool to automate the publication of // XML data through the Siena wide-area event notification system. // // See http://www.cs.colorado.edu/serl/siena/ // // Copyright (C) 2000-2001 University of Colorado // // Author: Antonio Carzaniga // See the file AUTHORS for full details. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, // USA, or send email to serl@cs.colorado.edu. // // $Id: XMLSubscriber.java,v 1.3 2001/01/24 17:08:37 carzanig Exp $ // import siena.*; import siena.sxml.*; // // a simple XML subscriber // class SimpleXMLSubscriber implements XMLNotifiable { // // does nothing but printing out the XML events it receives // public void notifyXml(String xml_event) { System.out.println("XML Event:\n" + xml_event); } // // does nothing at all with patterns of XML events // public void notifyXml(String[] xml_events) {}; } // // a simple subscriber // class SimpleSubscriber implements siena.Notifiable { // // extracts and prints the XML content from the Siena // notification, if the notification doesn't have any XML source, // prints the notification. // public void notify(Notification n) { String s; s = EventMap.getXmlText(n); if (s == null) s = n.toString(); System.out.println("Event:\n" + s); } // // does nothing with patterns // public void notify(Notification[] events) {}; } public class XMLSubscriber { public static void main(String args[]) { if (args.length != 1) { System.err.println("Usage: TestXMLNotifiable "); System.exit(1); } try { ThinClient siena = new ThinClient(args[0]); Filter f = new Filter(); f.addConstraint("name",Op.ANY,""); XMLNotifiableWrapper wrapper; wrapper = new XMLNotifiableWrapper(new SimpleXMLSubscriber()); siena.subscribe(f, wrapper); siena.subscribe(f, new SimpleSubscriber()); Thread.sleep(10000); siena.unsubscribe(wrapper); siena.shutdown(); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } System.exit(0); } }