providermanager.html

来自「开源项目smack的API文件」· HTML 代码 · 共 579 行 · 第 1/3 页

HTML
579 行
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_07) on Thu Jun 21 14:48:20 PDT 2007 --><TITLE>ProviderManager (Smack 3.0.4 Documentation)</TITLE><META NAME="keywords" CONTENT="org.jivesoftware.smack.provider.ProviderManager class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){    parent.document.title="ProviderManager (Smack 3.0.4 Documentation)";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">  <TR ALIGN="center" VALIGN="top">  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Smack</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="../../../../org/jivesoftware/smack/provider/PrivacyProvider.html" title="class in org.jivesoftware.smack.provider"><B>PREV CLASS</B></A>&nbsp;&nbsp;NEXT CLASS</FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">  <A HREF="../../../../index.html?org/jivesoftware/smack/provider/ProviderManager.html" target="_top"><B>FRAMES</B></A>  &nbsp;&nbsp;<A HREF="ProviderManager.html" target="_top"><B>NO FRAMES</B></A>  &nbsp;&nbsp;<SCRIPT type="text/javascript">  <!--  if(window==top) {    document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');  }  //--></SCRIPT><NOSCRIPT>  <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  SUMMARY:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">org.jivesoftware.smack.provider</FONT><BR>Class ProviderManager</H2><PRE><A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html" title="class or interface in java.lang">java.lang.Object</A>  <IMG SRC="../../../../resources/inherit.gif" ALT="extended by "><B>org.jivesoftware.smack.provider.ProviderManager</B></PRE><HR><DL><DT><PRE>public class <B>ProviderManager</B><DT>extends <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/Object.html" title="class or interface in java.lang">Object</A></DL></PRE><P>Manages providers for parsing custom XML sub-documents of XMPP packets. Two types of providers exist:<ul>      <li>IQProvider -- parses IQ requests into Java objects.      <li>PacketExtension -- parses XML sub-documents attached to packets into          PacketExtension instances.</ul> <b>IQProvider</b><p> By default, Smack only knows how to process IQ packets with sub-packets that are in a few namespaces such as:<ul>      <li>jabber:iq:auth      <li>jabber:iq:roster      <li>jabber:iq:register</ul> Because many more IQ types are part of XMPP and its extensions, a pluggable IQ parsing mechanism is provided. IQ providers are registered programatically or by creating a smack.providers file in the META-INF directory of your JAR file. The file is an XML document that contains one or more iqProvider entries, as in the following example: <pre> &lt;?xml version="1.0"?&gt; &lt;smackProviders&gt;     &lt;iqProvider&gt;         &lt;elementName&gt;query&lt;/elementName&gt;         &lt;namespace&gt;jabber:iq:time&lt;/namespace&gt;         &lt;className&gt;org.jivesoftware.smack.packet.Time&lt/className&gt;     &lt;/iqProvider&gt; &lt;/smackProviders&gt;</pre> Each IQ provider is associated with an element name and a namespace. If multiple provider entries attempt to register to handle the same namespace, the first entry loaded from the classpath will take precedence. The IQ provider class can either implement the IQProvider interface, or extend the IQ class. In the former case, each IQProvider is responsible for parsing the raw XML stream to create an IQ instance. In the latter case, bean introspection is used to try to automatically set properties of the IQ instance using the values found in the IQ packet XML. For example, an XMPP time packet resembles the following: <pre> &lt;iq type='result' to='joe@example.com' from='mary@example.com' id='time_1'&gt;     &lt;query xmlns='jabber:iq:time'&gt;         &lt;utc&gt;20020910T17:58:35&lt;/utc&gt;         &lt;tz&gt;MDT&lt;/tz&gt;         &lt;display&gt;Tue Sep 10 12:58:35 2002&lt;/display&gt;     &lt;/query&gt; &lt;/iq&gt;</pre> In order for this packet to be automatically mapped to the Time object listed in the providers file above, it must have the methods setUtc(String), setTz(String), and setDisplay(String). The introspection service will automatically try to convert the String value from the XML into a boolean, int, long, float, double, or Class depending on the type the IQ instance expects.<p> A pluggable system for packet extensions, child elements in a custom namespace for message and presence packets, also exists. Each extension provider is registered with a name space in the smack.providers file as in the following example: <pre> &lt;?xml version="1.0"?&gt; &lt;smackProviders&gt;     &lt;extensionProvider&gt;         &lt;elementName&gt;x&lt;/elementName&gt;         &lt;namespace&gt;jabber:iq:event&lt;/namespace&gt;         &lt;className&gt;org.jivesoftware.smack.packet.MessageEvent&lt/className&gt;     &lt;/extensionProvider&gt; &lt;/smackProviders&gt;</pre> If multiple provider entries attempt to register to handle the same element name and namespace, the first entry loaded from the classpath will take precedence. Whenever a packet extension is found in a packet, parsing will be passed to the correct provider. Each provider can either implement the PacketExtensionProvider interface or be a standard Java Bean. In the former case, each extension provider is responsible for parsing the raw XML stream to contruct an object. In the latter case, bean introspection is used to try to automatically set the properties of the class using the values in the packet extension sub-element. When an extension provider is not registered for an element name and namespace combination, Smack will store all top-level elements of the sub-packet in DefaultPacketExtension object and then attach it to the packet.<p> It is possible to provide a custom provider manager instead of the default implementation provided by Smack. If you want to provide your own provider manager then you need to do it before creating any <A HREF="../../../../org/jivesoftware/smack/XMPPConnection.html" title="class in org.jivesoftware.smack"><CODE>XMPPConnection</CODE></A> by sending the static <A HREF="../../../../org/jivesoftware/smack/provider/ProviderManager.html#setInstance(org.jivesoftware.smack.provider.ProviderManager)"><CODE>setInstance(ProviderManager)</CODE></A> message. Trying to change the provider manager after an XMPPConnection was created will result in an <A HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/IllegalStateException.html" title="class or interface in java.lang"><CODE>IllegalStateException</CODE></A> error.<P><P><DL><DT><B>Author:</B></DT>  <DD>Matt Tucker</DD></DL><HR><P><!-- ========== METHOD SUMMARY =========== -->

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?