public abstract class

AbstractExtension

extends Object
implements Extension
java.lang.Object
   ↳ com.google.gdata.data.AbstractExtension
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Common extension implementation for sharing code among implementers of Extension. The information contained in this class is:

  1. XML namespace of the extension
  2. XML local name of the extension
  3. if the extension is mutable

Summary

Nested Classes
class AbstractExtension.AttributesHandler Base class for custom element handlers that uses AttributeHelper to consume the attributes and the element's text content. 
Fields
private final String extensionLocalName
private final XmlNamespace extensionNamespace
private boolean immutable Indicates that the extension is constant after construction (false by default).
protected final String localName XML local name for this extension or null if not defined
protected final XmlNamespace namespace XML namespace for this extension or null if not defined
private static ThreadLocal<Boolean> strictValidation Indicates if strict XML parsing/generation validation enabled/disabled
Protected Constructors
AbstractExtension()
Constructs an extension bound to a specific XML representation.
AbstractExtension(XmlNamespace namespace, String localName)
Constructs an extension bound to a specific XML representation.
Public Methods
final static void disableStrictValidation()
final static void enableStrictValidation()
void generate(XmlWriter w, ExtensionProfile p)
Generates an XML representation for the extension.
final String getExtensionLocalName()
Gets the extension's localname.
final XmlNamespace getExtensionNamespace()
Gets the extension's namespace.
XmlParser.ElementHandler getHandler(ExtensionProfile p, String namespace, String localName, Attributes attrs)
The default implementation uses the AbstractExtension.AttributesHandler to handle parsing the extension.
final boolean isImmutable()
final static boolean isStrictValidation()
final void setImmutable(boolean isImmutable)
Protected Methods
void consumeAttributes(AttributeHelper helper)
Consumes attributes from the attribute helper.
static boolean eq(Object o1, Object o2)
void generate(XmlWriter w, ExtensionProfile p, XmlNamespace namespace, String localName, List<XmlWriter.Attribute> attrs, AttributeGenerator generator)
Generates the XML into the XML writer.
void generateAttributes(List<XmlWriter.Attribute> attrs, AttributeGenerator generator)
Generates the attributes in the generator into the list of attributes.
void putAttributes(AttributeGenerator generator)
Puts attributes into the attribute generator.
boolean sameClassAs(Object o)
final static void throwExceptionForMissingAttribute(String attrName)
Throws an IllegalStateException if the value is required and it is missing.
final void throwExceptionIfImmutable()
Throws an IllegalStateException if this instance is immutable.
void validate()
Checks the attributes to see if there are any problems.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.gdata.data.Extension

Fields

private final String extensionLocalName

private final XmlNamespace extensionNamespace

private boolean immutable

Indicates that the extension is constant after construction (false by default).

protected final String localName

XML local name for this extension or null if not defined

protected final XmlNamespace namespace

XML namespace for this extension or null if not defined

private static ThreadLocal<Boolean> strictValidation

Indicates if strict XML parsing/generation validation enabled/disabled

Protected Constructors

protected AbstractExtension ()

Constructs an extension bound to a specific XML representation. The concrete subclass must have an ExtensionDescription.Default attribute defined to use this constructor.

protected AbstractExtension (XmlNamespace namespace, String localName)

Constructs an extension bound to a specific XML representation. Note: this is here for backwards compatibility and may be removed at some point in the future.

Parameters
namespace The namespace of the value element
localName The local name of the value element

Public Methods

public static final void disableStrictValidation ()

public static final void enableStrictValidation ()

public void generate (XmlWriter w, ExtensionProfile p)

Generates an XML representation for the extension.

Parameters
w XML writer
p Extension profile
Throws
IOException

public final String getExtensionLocalName ()

Gets the extension's localname.

public final XmlNamespace getExtensionNamespace ()

Gets the extension's namespace.

public XmlParser.ElementHandler getHandler (ExtensionProfile p, String namespace, String localName, Attributes attrs)

The default implementation uses the AbstractExtension.AttributesHandler to handle parsing the extension.

Parameters
p Extension profile
namespace Extension namespace
localName Tag name, without the namespace prefix
attrs Tag attributes
Returns
  • an element handler
Throws
ParseException when an unexpected tag or badly-formatted XML is detected

public final boolean isImmutable ()

public static final boolean isStrictValidation ()

public final void setImmutable (boolean isImmutable)

Parameters
isImmutable

Protected Methods

protected void consumeAttributes (AttributeHelper helper)

Consumes attributes from the attribute helper. May also use consumeContent(boolean) to consume the element's text content. Called from getHandler(ExtensionProfile, String, String, Attributes). Default implementation does nothing, though generally this is discouraged unless there really are no attributes.

Parameters
helper Attribute helper
Throws
ParseException any parsing exception

protected static boolean eq (Object o1, Object o2)

Parameters
o1 Object 1 or null
o2 Object 2 or null
Returns
  • true if the specified arguments are equal, or both null

protected void generate (XmlWriter w, ExtensionProfile p, XmlNamespace namespace, String localName, List<XmlWriter.Attribute> attrs, AttributeGenerator generator)

Generates the XML into the XML writer. Default implementation generates a "simple" element with the attributes and content found in the attribute generator.

Parameters
w XML writer
p Extension profile
namespace XML namespace for this extension
localName XML local name for this extension
attrs List of XML attributes
generator Attribute generator
Throws
IOException any I/O exception

protected void generateAttributes (List<XmlWriter.Attribute> attrs, AttributeGenerator generator)

Generates the attributes in the generator into the list of attributes.

Parameters
attrs
generator

protected void putAttributes (AttributeGenerator generator)

Puts attributes into the attribute generator. Called from generate(XmlWriter, ExtensionProfile). Default implementation does nothing, though generally this is discouraged unless there really are no attributes.

Parameters
generator Attribute generator

protected boolean sameClassAs (Object o)

Parameters
o Given object
Returns
  • true if the given object is not null and is the same concrete class as this one

protected static final void throwExceptionForMissingAttribute (String attrName)

Throws an IllegalStateException if the value is required and it is missing.

Parameters
attrName Attribute name
Throws
IllegalStateException to indicate that there are problems with the attributes

protected final void throwExceptionIfImmutable ()

Throws an IllegalStateException if this instance is immutable. Should only be used in a value-setter method.

protected void validate ()

Checks the attributes to see if there are any problems. Default implementation does nothing, though generally this is discouraged unless there really are no restrictions.

Throws
IllegalStateException if any problems are found with the attributes