public final class

MetadataRegistry

extends Object
java.lang.Object
   ↳ com.google.gdata.model.MetadataRegistry

Class Overview

A mutable, thread-safe registry for metadata. This should be used to construct the default metadata for elements and attributes, the transforms on those default metadata instances, and any adaptations on the element types. The createSchema() method can be called to construct an immutable Schema from this builder.

Thread safety is guaranteed by always guarding access to the element and attribute maps by synchronizing on the builder itself. The individual element and attribute registries are also thread safe.

Summary

Fields
private final Map<Schema.RootKey, AttributeMetadataRegistryBuilder> attributes
private Schema cachedSchema
private final Map<Schema.RootKey, ElementMetadataRegistryBuilder> elements
Public Constructors
MetadataRegistry()
Constructs a new empty metadata registry.
MetadataRegistry(MetadataRegistry source)
Copy constructor, creates a copy of the given metadata registry.
Public Methods
<D, E extends Element> void adapt(ElementKey<D, E> source, String kind, ElementKey<? extends D, ? extends E> adaptation)
Adapts from the source type to the adaptation type on the given kind.
AttributeCreator build(ElementKey<?, ?> parent, AttributeKey<?> attribute)
Builds the metadata for the attribute inside the parent.
ElementCreator build(ElementKey<?, ?> element, MetadataContext context)
Builds metadata for when the key is used in a context compatible with context.
ElementCreator build(ElementKey<?, ?> element)
Builds element metadata for the given key.
AttributeCreator build(ElementKey<?, ?> parent, AttributeKey<?> attribute, MetadataContext context)
Builds the metadata for the attribute inside the parent, during the context.
ElementCreator build(ElementKey<?, ?> parent, ElementKey<?, ?> element, MetadataContext context)
Builds metadata for when the key is inside the parent and used in a context compatible with context.
ElementCreator build(ElementKey<?, ?> parent, ElementKey<?, ?> element)
Builds metadata for when the key is inside the parent.
Schema createSchema()
Creates a Schema out of this registry.
boolean isRegistered(ElementKey<?, ?> key)
Returns true if the given key has already been registered.
synchronized MetadataRegistry merge(MetadataRegistry other)
Merges another metadata registry into this metadata registry.
MetadataRegistry register(ElementKey<?, ?> key)
Registers the metadata for an element key.
synchronized MetadataRegistry registerClass(Class<? extends Element> clazz)
Registers the metadata from an element subclass using its "registerMetadata" method through reflection.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private final Map<Schema.RootKey, AttributeMetadataRegistryBuilder> attributes

private Schema cachedSchema

private final Map<Schema.RootKey, ElementMetadataRegistryBuilder> elements

Public Constructors

public MetadataRegistry ()

Constructs a new empty metadata registry.

public MetadataRegistry (MetadataRegistry source)

Copy constructor, creates a copy of the given metadata registry. This is equivalent to new MetadataRegistry().merge(source).

Parameters
source

Public Methods

public void adapt (ElementKey<D, E> source, String kind, ElementKey<? extends D, ? extends E> adaptation)

Adapts from the source type to the adaptation type on the given kind.

Parameters
source
kind
adaptation

public AttributeCreator build (ElementKey<?, ?> parent, AttributeKey<?> attribute)

Builds the metadata for the attribute inside the parent. Note that this will not declare the attribute as part of the parent element, that must be done using addAttribute(AttributeKey) or replaceAttribute(AttributeKey).

Parameters
parent
attribute

public ElementCreator build (ElementKey<?, ?> element, MetadataContext context)

Builds metadata for when the key is used in a context compatible with context.

Parameters
element
context

public ElementCreator build (ElementKey<?, ?> element)

Builds element metadata for the given key. This will create the default metadata for that key. If the key's element type has a superclass with existing metadata registered at the same ID, the new key will inherit any existing properties.

Parameters
element

public AttributeCreator build (ElementKey<?, ?> parent, AttributeKey<?> attribute, MetadataContext context)

Builds the metadata for the attribute inside the parent, during the context. Note that this will not declare the attribute as part of the parent element, that must be done using addAttribute(AttributeKey) or replaceAttribute(AttributeKey).

Parameters
parent
attribute
context

public ElementCreator build (ElementKey<?, ?> parent, ElementKey<?, ?> element, MetadataContext context)

Builds metadata for when the key is inside the parent and used in a context compatible with context. Note that this will not declare the element as part of the parent element, that must be done using addElement(ElementKey) or replaceElement(ElementKey).

This will also guarantee that any element types that are referenced have been registered in this registry.

Parameters
parent
element
context

public ElementCreator build (ElementKey<?, ?> parent, ElementKey<?, ?> element)

Builds metadata for when the key is inside the parent. Note that this will not declare the element as part of the parent element, that must be done using addElement(ElementKey) or replaceElement(ElementKey).

Parameters
parent
element

public Schema createSchema ()

Creates a Schema out of this registry. Will return a cached instance if the registry has not changed since last time create() was called.

public boolean isRegistered (ElementKey<?, ?> key)

Returns true if the given key has already been registered. This is used to prevent reentrant metadata registration (and cycles).

Parameters
key

public synchronized MetadataRegistry merge (MetadataRegistry other)

Merges another metadata registry into this metadata registry. Both registries are locked during this time, first this registry and then the other registry. Do not attempt to do a.merge(b) and b.merge(a) in separate threads at the same time or a deadlock may occur.

Parameters
other

public MetadataRegistry register (ElementKey<?, ?> key)

Registers the metadata for an element key. This will call the "registerMetadata" method on the Element subclass that the key refers to, if it refers to a subclass. If it refers to Element directly it will just build the key.

Parameters
key
Throws
IllegalArgumentException if the element type does not support a registration method.

public synchronized MetadataRegistry registerClass (Class<? extends Element> clazz)

Registers the metadata from an element subclass using its "registerMetadata" method through reflection.

Parameters
clazz