Class Extension
- java.lang.Object
-
- rocks.xmpp.core.session.Extension
-
- All Implemented Interfaces:
ExtensionProtocol
,DiscoverableInfo
public final class Extension extends Object implements ExtensionProtocol, DiscoverableInfo
Represents an XMPP protocol extension (XEP).An extension usually consists of:
- A namespace, which uniquely identifies the extension, e.g.
"urn:xmpp:receipts"
- A
Manager
class, which is associated with the extension and manages its business logic. - A collection of classes which are implementations of the XML schema.
- A set of features, which are advertised together with the namespace in service discovery, e.g. "urn:xmpp:hash-function-text-names:sha-1"
All of these characteristics are optional:
An extension could have an XML schema implementation, but no business logic and therefore no manager class, like XEP-0203: Delayed Delivery.
The namespace is optional as well: If an extension has no namespace, it won't be advertised in Service Discovery.
Extensions which have business logic (and hence a manager class), can be enabled or disabled.
In order to create an extension, use one of its static factory methods.
This class overrides
equals(Object)
andhashCode()
, so that two extensions are considered equal if either their namespace are equal or their manager classes. This allows to disable certain extensions or managers by default.- See Also:
- XEP-0030: Service Discovery
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Collection<Class<?>>
getClasses()
Gets the collection of classes, which represent the extension's XML schema implementation.Set<String>
getFeatures()
Gets the collection of "sub" features, which are associated with the extension.Class<?>
getManager()
Gets the manager class.String
getNamespace()
Gets the protocol namespace.int
hashCode()
boolean
isEnabled()
Indicates whether the extension is enabled or not.static Extension
of(Class<?>... classes)
Creates an extension with a set of classes (XML schema implementations) used by this extension.static Extension
of(Class<?> manager, boolean enabled)
Creates an extension, which won't get advertised during service discovery and only has a manager class.static Extension
of(String namespace, boolean enabled, Class<?>... classes)
Creates an extension without business logic, but an XML schema class.static Extension
of(String namespace, Class<?> manager, boolean enabled, Class<?>... classes)
Creates an extension with a namespace, business logic and XML schema classes.static Extension
of(String namespace, Class<? extends Manager> manager, boolean notify, boolean enabled, Class<?>... classes)
Creates an PEP (Personal Eventing Protocol) extension with a namespace, business logic and XML schema classes.static Extension
of(String namespace, Class<? extends Manager> manager, Set<String> features, boolean enabled, Class<?>... classes)
Creates an extension which can advertise additional features, such as XEP-0300.String
toString()
-
Methods inherited from interface rocks.xmpp.extensions.disco.model.info.DiscoverableInfo
getExtensions, getIdentities
-
-
-
-
Method Detail
-
of
public static Extension of(Class<?>... classes)
Creates an extension with a set of classes (XML schema implementations) used by this extension.Use it for extensions without business logic and no namespace which needs to be advertised, e.g. for Delayed Delivery.
- Parameters:
classes
- The classes.- Returns:
- The extension.
-
of
public static Extension of(Class<?> manager, boolean enabled)
Creates an extension, which won't get advertised during service discovery and only has a manager class.- Parameters:
manager
- The manager class.enabled
- If this manager is enabled.- Returns:
- The extension.
-
of
public static Extension of(String namespace, boolean enabled, Class<?>... classes)
Creates an extension without business logic, but an XML schema class. If enabled, it will be advertised as a feature in service discovery. Examples are XEP-0020, XEP-0122 or XEP-0141.- Parameters:
namespace
- The protocol namespace.enabled
- If this extension is enabled, i.e. whether it's advertised in service discovery.classes
- The XML schema classes.- Returns:
- The extension.
-
of
public static Extension of(String namespace, Class<?> manager, boolean enabled, Class<?>... classes)
Creates an extension with a namespace, business logic and XML schema classes.This is the most common extension characteristic.
- Parameters:
namespace
- The protocol namespace.manager
- The manager class, which covers the business logic.enabled
- If this extension is enabled, i.e. whether its manager class is enabled and whether it's advertised in service discovery.classes
- The XML schema classes.- Returns:
- The extension.
-
of
public static Extension of(String namespace, Class<? extends Manager> manager, boolean notify, boolean enabled, Class<?>... classes)
Creates an PEP (Personal Eventing Protocol) extension with a namespace, business logic and XML schema classes.- Parameters:
namespace
- The protocol namespace.manager
- The manager class, which covers the business logic.notify
- True, if this feature should be advertised along with a "filtered notification", i.e. as "namespace+notify".enabled
- If this extension is enabled, i.e. whether its manager class is enabled and whether it's advertised in service discovery.classes
- The XML schema classes.- Returns:
- The extension.
-
of
public static Extension of(String namespace, Class<? extends Manager> manager, Set<String> features, boolean enabled, Class<?>... classes)
Creates an extension which can advertise additional features, such as XEP-0300.- Parameters:
namespace
- The protocol namespace.manager
- The manager class, which covers the business logic.features
- The features, which are advertised in service discovery.enabled
- If this extension is enabled, i.e. whether its manager class is enabled and whether it's advertised in service discovery.classes
- The XML schema classes.- Returns:
- The extension.
-
getNamespace
public final String getNamespace()
Gets the protocol namespace.- Specified by:
getNamespace
in interfaceExtensionProtocol
- Returns:
- The protocol namespace or null.
-
getManager
public final Class<?> getManager()
Gets the manager class.- Returns:
- The manager class or null.
-
getClasses
public final Collection<Class<?>> getClasses()
Gets the collection of classes, which represent the extension's XML schema implementation.- Returns:
- The classes.
-
getFeatures
public final Set<String> getFeatures()
Gets the collection of "sub" features, which are associated with the extension.- Specified by:
getFeatures
in interfaceDiscoverableInfo
- Returns:
- The features.
-
isEnabled
public final boolean isEnabled()
Indicates whether the extension is enabled or not.- Specified by:
isEnabled
in interfaceExtensionProtocol
- Returns:
- True, if the extension is enabled; false if disabled.
-
-