2015-03-12 13:12:39 +01:00
General Rules
=============
All classes which subclass `TopLevelStreamElement` and `ExtensionElement` must either
1. be immutable (and ideally provide a Builder)
2. implemented `TypedCloneable`
and must be `Serializable` .
The reason that it must be either 1. or 2. is that it makes no sense to clone an inmutable instance.
Note that there is legacy code in Smack which does not follow these rules. Patches welcome.
ExtensionElement
================
Extension elements are XML elements that are used in various parts and levels of stanzas.
2014-09-16 22:14:10 +02:00
2015-02-26 18:41:17 +01:00
The static `from(Stanza)` Method
2014-09-16 22:14:10 +02:00
--------------------------------
2015-03-12 13:12:39 +01:00
Every ExtensionElement class must have a static `from()` method that retrieves that extension for a given Stanza (if any).
2014-09-16 22:14:10 +02:00
Sample Code
```java
2015-02-26 18:41:17 +01:00
public static RSMSet from(Stanza) {
2014-09-16 22:14:10 +02:00
return packet.getExtension(ELEMENT, NAMESPACE);
}
```
2015-03-12 13:12:39 +01:00
Sometimes certain ExtensionElement's are only found in one stanza type, in that case, specify the parameter type. For example `public static CarbonExtension getFrom(Message)` .