if (element == null)
{
if (keyHint != null)
{
KeyValue<String, Element> kvPair = new DefaultKeyValue(keyHint, null, true);
this.headElements.remove(kvPair);
}
else
{
// If element is null and keyHint is null, remove all head elements.
// This is complying with the portlet spec.
this.headElements.clear();
}
return;
}
if (!(element instanceof Serializable))
{
throw new NotSerializableException("The element is not serializable.");
}
if (keyHint == null)
{
// If element is dom4j's element, then we can use dom4j's serializer.
// Meanwhile, the element can be a serializable one which is not from dom4j.
// In the case, serialize the element to a string as a keyHint.
if (element instanceof org.dom4j.Element)
{
keyHint = DOMUtils.stringifyElement((org.dom4j.Element) element);
}
else
{
keyHint = DOMUtils.stringifyElement(element);
}
}
KeyValue<String, Element> kvPair = new DefaultKeyValue(keyHint, element, true);
if (!this.headElements.contains(kvPair))
{
this.headElements.add(kvPair);
}