Class Jabber::XMPPElement
In: lib/xmpp4r/xmppelement.rb
Parent: REXML::Element
Message Presence XMPPStanza Iq XMPPElement X IqQuery Error Singleton IdGenerator Connection Client Component Client Comparable JID RuntimeError ErrorException AuthenticationFailure NoNameXmlnsRegistered SOCKS5Error REXML::Element Stream SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator XMPPElement StreamHost IqSiFileRange IqSiFile StreamHostUsed IqSi IqFeature XRosterItem RosterItem XMUCUserItem XMUCUserInvite IqPubSub Items Subscription IqPubSubOwner Item Event Feature Identity Item XDataField XDataReported XDataTitle XDataInstructions IqVcard SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IqQuery IqQueryBytestreams IqQueryVersion IqQueryRoster IqQueryRPC IqQueryMUCOwner IqQueryDiscoItems IqQueryDiscoInfo IBB IBBTarget IBBInitiator Responder SimpleResponder Iq IqCommand RosterXItem XRoster RosterX X XMUCUser XMUC XDelay XData XMLRPC::ParserWriterChooseMixin Client Server XMLRPC::ParseContentType XMLRPC::BasicServer XParent MUCClient SimpleMUCClient Base DigestMD5 Plain FileSource ServiceHelper NodeHelper CallbackList Callback Semaphore StreamParser SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Responder Helper MUCBrowser Helper NodeBrowser Helper lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/xmppstanza.rb lib/xmpp4r/callbacks.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/connection.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/semaphore.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/x.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/query.rb lib/xmpp4r/xmppelement.rb lib/xmpp4r/message.rb lib/xmpp4r/presence.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb Bytestreams XParent lib/xmpp4r/version/iq/version.rb lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb Version lib/xmpp4r/command/iq/command.rb lib/xmpp4r/command/helper/responder.rb Command lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb lib/xmpp4r/roster/x/roster.rb Roster lib/xmpp4r/rpc/helper/server.rb lib/xmpp4r/rpc/helper/client.rb lib/xmpp4r/rpc/iq/rpc.rb RPC lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/helper/mucclient.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/iq/mucowner.rb lib/xmpp4r/muc/helper/simplemucclient.rb MUC lib/xmpp4r/sasl.rb SASL lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/pubsub/stanzas/subscription.rb lib/xmpp4r/pubsub/helper/servicehelper.rb lib/xmpp4r/pubsub/stanzas/item.rb lib/xmpp4r/pubsub/helper/nodehelper.rb lib/xmpp4r/pubsub/iq/pubsub.rb lib/xmpp4r/pubsub/stanzas/event.rb lib/xmpp4r/pubsub/helper/nodebrowser.rb lib/xmpp4r/pubsub/stanzas/items.rb PubSub lib/xmpp4r/httpbinding/client.rb HTTPBinding lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_81_0.png

This class represents an XML element and provides functionality for automatic casting of XML element classes according to their element name and namespace.

Deriving classes must met these criteria:

  • The element name and namespace must be specified by calling the name_xmlns class method
  • The class constructor must be callable with no mandatory parameter

Methods

Public Class methods

Find a class for given name and namespace

name:[String]
xmlns:[String]
result:A descendant of XMPPElement or REXML::Element

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 75
75:     def self.class_for_name_xmlns(name, xmlns)
76:       if @@name_xmlns_classes.has_key? [name, xmlns]
77:         @@name_xmlns_classes[[name, xmlns]]
78:       elsif @@name_xmlns_classes.has_key? [name, nil]
79:         @@name_xmlns_classes[[name, nil]]
80:       else
81:         REXML::Element
82:       end
83:     end

Set whether this element is always built with an xmlns attribute

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 40
40:     def self.force_xmlns(force)
41:       @@force_xmlns = force
42:     end

Whether this element is always built with an xmlns attribute

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 46
46:     def self.force_xmlns?
47:       @@force_xmlns
48:     end

Import another REXML::Element descendant to:

  • Either an element class that registered with name and xmlns before
  • Or if none was found to the class itself (you may call this class method on a deriving class)

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 91
91:     def self.import(element)
92:       klass = class_for_name_xmlns(element.name, element.namespace)
93:       if klass != self and klass.ancestors.include?(self)
94:         klass.new.import(element)
95:       else
96:         self.new.import(element)
97:       end
98:     end

Specify XML element name and xmlns for a deriving class, this pair and the class will be added to a global pool

If the namespace is nil the class is a "wildcard class" matching elements with any xmlns if no other class with that namespace was defined

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 34
34:     def self.name_xmlns(name, xmlns=nil)
35:       @@name_xmlns_classes[[name, xmlns]] = self
36:     end

Find the name and namespace for a given class. This class must have registered these two values by calling name_xmlns at definition time.

Raises an exception if none was found

klass:[Class]
result:[String, String] name and namespace

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 58
58:     def self.name_xmlns_for_class(klass)
59:       klass.ancestors.each do |klass1|
60:         @@name_xmlns_classes.each do |name_xmlns,k|
61:           if klass1 == k
62:             return name_xmlns
63:           end
64:         end
65:       end
66: 
67:       raise NoNameXmlnsRegistered.new(klass)
68:     end

Initialize this element, which will then be initialized with the name registered with name_xmlns.

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 103
103:     def initialize(*arg)
104:       if arg.empty?
105:         name, xmlns = self.class::name_xmlns_for_class(self.class)
106:         super(name)
107:         if self.class::force_xmlns?
108:           add_namespace(xmlns)
109:         end
110:       else
111:         super
112:       end
113:     end

Public Instance methods

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 145
145:     def clone
146:       cloned = self.class.new
147:       cloned.add_attributes self.attributes.clone
148:       cloned.context = @context
149:       cloned
150:     end

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 133
133:     def parent=(new_parent)
134:       if parent and parent.namespace('') == namespace('') and attributes['xmlns'].nil?
135:         add_namespace parent.namespace('')
136:       end
137: 
138:       super
139: 
140:       if new_parent and new_parent.namespace('') == namespace('')
141:         delete_namespace
142:       end
143:     end

Add a child element which will be imported according to the child‘s name and xmlns

element:[REXML::Element] Child
result:[REXML::Element or descendant of XMPPElement] New child

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 120
120:     def typed_add(element)
121:       if element.kind_of? REXML::Element
122:         element_ns = (element.namespace.to_s == '') ? namespace : element.namespace
123: 
124:         klass = XMPPElement::class_for_name_xmlns(element.name, element_ns)
125:         if klass != element.class
126:           element = klass.import(element)
127:         end
128:       end
129: 
130:       super(element)
131:     end

[Validate]