Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: edu/ou/kmi/buddyspace/xml/IQServicesHandler.java


1   /*
2    *   License
3    *
4    * The contents of this file are subject to the Jabber Open Source License
5    * Version 1.0 (the "License").  You may not copy or use this file, in either
6    * source code or executable form, except in compliance with the License.  You
7    * may obtain a copy of the License at http://www.jabber.com/license/ or at
8    * http://www.opensource.org/.  
9    *
10   * Software distributed under the License is distributed on an "AS IS" basis,
11   * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
12   * for the specific language governing rights and limitations under the
13   * License.
14   *
15   *   Copyrights
16   *
17   * Portions created by or assigned to Jabber.com, Inc. are 
18   * Copyright (c) 2000 Jabber.com, Inc.  All Rights Reserved.  Contact
19   * information for Jabber.com, Inc. is available at http://www.jabber.com/.
20   *
21   * Portions Copyright (c) 1999-2000 David Waite 
22   *
23   *   Acknowledgements
24   * 
25   * Special thanks to the Jabber Open Source Contributors for their
26   * suggestions and support of Jabber.
27   * 
28   *   Changes
29   *
30   * @author  $Author: brouk $
31   * @version $Revision: 1.1 $
32   *
33   * j.komzak
34   * Changed in IQServicesHandler for BuddySpace services namespace.
35   */
36  
37  package edu.ou.kmi.buddyspace.xml;
38  
39  import org.jabber.jabberbeans.sax.HandlerFactory;
40  import org.jabber.jabberbeans.sax.SubHandler;
41  import org.jabber.jabberbeans.Extension.Extension;
42  import org.jabber.jabberbeans.sax.Extension.HashExtensionHandler;
43  import org.xml.sax.SAXException;
44  import org.xml.sax.AttributeList;
45  
46  /**
47   * Handler class to build jabber:iq:register objects. All work is
48   * done by the HashExtensionHandler.
49   *
50   * @author  David Waite <a href="mailto:dwaite@jabber.com">
51   *                      <i>&lt;dwaite@jabber.com&gt;</i></a>
52   * @author  $Author: brouk $
53   * @version $Revision: 1.1 $ 
54   *
55   * @author  Jiri Komzak <a href="mailto:j.komzak@open.ac.uk">
56   *                      <i>&lt;j.komzak@open.ac.uk&gt;</i></a>
57   * @author  $Author: brouk $
58   * @version $Revision: 1.1 $
59   */
60  public class IQServicesHandler extends HashExtensionHandler {
61      
62      /** StringBuffer holding data between elements */
63      //protected StringBuffer elementChars;
64      
65      /** builder to construct the product extension object */
66      //protected IQServicesBuilder builder;
67  
68      /**
69       * Creates a new <code>IQServicesHandler</code> instance.
70       */
71      public IQServicesHandler() 
72      {
73          super();
74          builder = new IQServicesBuilder();
75      }
76      
77      /**
78       * Gets called when the underlying engine decides to pass an entity and
79       * all sub-entities off to your subhandler.<p>
80       *
81       * Upon seeing the element that this subhandler handles, we call this
82       * constructor, passing in the attributes.
83       *
84       * @param name name of the element which we are handling.
85       * @param attributes list of attributes on this element
86       */
87      protected void startHandler(String name, AttributeList attributes)
88    throws SAXException
89      { 
90    elementChars=new StringBuffer();
91    builder.reset();
92          
93          if("query".equals(name))
94              ((IQServicesBuilder)builder).setIQ(true);
95          else
96              ((IQServicesBuilder)builder).setIQ(false);
97      }
98          
99      
100     /*
101      * <code>handleStartElement</code> is overloaded by the new class to
102      * provide logic to handle the element code.
103      *
104      * @param name a <code>String</code> value
105      * @param attributes an <code>AttributeList</code> value
106      * @exception SAXException if an error occurs
107      */
108     protected void handleStartElement(String name, AttributeList attributes) throws SAXException
109     {      
110             elementChars=new StringBuffer();
111 
112             //Start new handler for items that *may* be containers, but never for namespaces "ns".
113             if("x".equals(name) && 
114                "jabber:x:data".equals(attributes.getValue("xmlns")))
115                 
116                 setChildSubHandler(new XDataHandler(), name, attributes);
117             //setChildSubHandler(new LayerTagHandler(), name, attributes);
118             
119             // if this is has a handler, we switch off to it.
120             /*HandlerFactory hf = getHandlerFactory();
121             SubHandler newHandler = hf.getHandlerInstance(name, attributes);
122             if (newHandler != null) {
123                 setChildSubHandler(newHandler, name, attributes);
124                 return;
125             }*/
126     }
127 
128     
129     /*
130      * <code>receiveChildData</code> is called when a child handler exits,
131      * returning control to this code. The now-defunct handler along with the
132      * data object are both returned.
133      *
134      * @param subHandler a <code>SubHandler</code> value
135      * @param o an <code>Object</code> value
136      */
137     protected void receiveChildData(SubHandler subHandler, Object o)
138     {
139             //Add the returned object to the child vector
140             ((IQServicesBuilder)builder).addExtension((Extension)o);
141     }
142   
143 }