Source code: edu/ou/kmi/buddyspace/xml/IQServices.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 into IQServices
35 */
36
37 package edu.ou.kmi.buddyspace.xml;
38
39 import java.util.*;
40 import org.jabber.jabberbeans.Extension.Extension;
41 import org.jabber.jabberbeans.Extension.HashExtension;
42 import org.jabber.jabberbeans.Extension.QueryExtension;
43
44 /**
45 * An <code>IQSerices</code> holds the values for BuddySpace services namespace
46 *
47 * @author David Waite <a href="mailto:dwaite@jabber.com">
48 * <i><dwaite@jabber.com></i></a>
49 * @author $Author: brouk $
50 * @version $Revision: 1.1 $
51 *
52 * @author Jiri Komzak <a href="mailto:j.komzak@open.ac.uk">
53 * <i><j.komzak@open.ac.uk></i></a>
54 * @author $Author: brouk $
55 * @version $Revision: 1.1 $
56 */
57 public class IQServices extends HashExtension
58 implements QueryExtension {
59
60 /** Vector of extension objects contained. */
61 private Vector extensions;
62
63 /** is this query or x **/
64 private boolean iq;
65
66 /** Creates a new <code>IQServices</code> instance. */
67 public IQServices(IQServicesBuilder builder)
68 throws InstantiationException
69 {
70 super(builder);
71 extensions = (Vector) builder.extensions().clone();
72 iq = builder.isIQ();
73 }
74
75 /**
76 * Used to fetch the internal XMLNS, which is used by AppendItem and
77 * toString to return the proper XML representation.
78 *
79 * @return <code>String</code> holding the XML namespace
80 */
81 protected String getXMLNS()
82 {
83 return "http://jabber.open.ac.uk/tags/services";
84 }
85
86
87 public boolean isIQ() {
88 return iq;
89 }
90
91
92 /**
93 * returns an enumeration of <code>extensions</code> contained within this
94 * object.
95 *
96 * @return an <code>Enumeration</code> value
97 */
98 public Enumeration extensions()
99 {
100 return extensions.elements();
101 }
102
103
104 /**
105 * <code>appendItem</code> appends the XML representation of the
106 * current packet data to the specified <code>StringBuffer</code>.
107 *
108 * @param retval The <code>StringBuffer</code> to append to
109 */
110 public void appendItem(StringBuffer retval)
111 {
112 retval.append("<" + (iq? "query" : "x") + " xmlns=\"");
113 retval.append(getXMLNS());
114 retval.append("\">");
115
116 Enumeration names=entries.keys();
117 if (names!=null)
118 {
119 while (names.hasMoreElements())
120 {
121 String name=(String)names.nextElement();
122 appendChild(retval,
123 name,
124 (String)entries.get(name));
125 }
126 }
127
128 Enumeration extEnum = extensions.elements();
129 while (extEnum.hasMoreElements()) {
130 Extension ext = (Extension) extEnum.nextElement();
131 ext.appendItem(retval);
132 }
133
134 retval.append("</" + (iq? "query" : "x") + ">");
135 }
136
137 }