XmlElement.java

  1. /**
  2.  *
  3.  * Copyright 2018-2021 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smack.packet;

  18. import javax.xml.namespace.QName;

  19. /**
  20.  * Interface to represent XML elements. Every XML element in XMPP has a qualified XML name ({@link QName}). This name
  21.  * can be obtained via {@link #getQName()}.
  22.  * <p>
  23.  * XMPP uses "extension elements", i.e. XML elements, to provide extended functionality beyond what is in the base XMPP
  24.  * specification. Examples of extensions elements include message events, message properties, and extra presence data.
  25.  * IQ stanzas have limited support for extension elements. See {@link ExtensionElement} for more information about XMPP
  26.  * extension elements.
  27.  * </p>
  28.  * <p>
  29.  * It is recommend to use {@link ExtensionElement} over this class when creating new extension elements.
  30.  * </p>
  31.  *
  32.  * @see org.jivesoftware.smack.provider.ExtensionElementProvider
  33.  * @since 4.5
  34.  */
  35. public interface XmlElement extends NamedElement, XmlLangElement {

  36.     /**
  37.      * Returns the root element XML namespace.
  38.      *
  39.      * @return the namespace.
  40.      */
  41.     String getNamespace();

  42.     default QName getQName() {
  43.         String namespaceURI = getNamespace();
  44.         String localPart = getElementName();
  45.         return new QName(namespaceURI, localPart);
  46.     }

  47.     @Override
  48.     default String getLanguage() {
  49.         return null;
  50.     }
  51. }