public class

AltRegistry

extends Object
java.lang.Object
   ↳ com.google.gdata.wireformats.AltRegistry

Class Overview

The AltRegistry class maintains a registry of supported alternate representation formats along with the configuration of input and output handlers that will be used to process wire format content using the representations.

The registry supports a delegation model where lookup failures can be delegated to a different registry to support tiered lookup models. It also has a locking model to avoid changes occurring after initialization has been completed.

The class provides a locking model where the contents of the registry can be made immutable using the lock() method. After this call, no subsequent changes may be made to the registry and it is thread safe to share across multiple threads.

Summary

Fields
private final Map<AltFormat, AltRegistry.AltHandlers> altHandlers Contains a mapping from an alt format instance to the configuration for the format
private AltRegistry delegate If non-null, contains a default registry that will be used as a delegate for all lookups that cannot be satisfied by this instance.
private boolean locked If true, indicates that the registry is locked against further changes.
private final Map<String, AltFormat> nameMap Contains a mapping from alt parameter name values to the associated format instance selected by each name.
private final Map<String, AltFormat> typeMap Contains a mapping from alt parameter media type names to an alt format that represents the alternate content representation type selected by the media type.
Public Constructors
AltRegistry()
Constructs a new AltRegistry with no default registry configuration.
AltRegistry(AltRegistry origRegistry)
Constructs a new AltRegistry with identical registration state to the provided registry.
Public Methods
OutputGenerator<?> getGenerator(AltFormat altFormat)
Returns the OutputGenerator for the provided format or null if the format is not registered.
InputParser<?> getParser(AltFormat altFormat)
Returns the InputParser for a format or null if the format is not registered or does not support input parsing.
boolean hasSameHandlers(AltRegistry targetRegistry, AltFormat altFormat)
Returns true has an identical registration with the target registry for the specified alt format.
void lock()
Locks the registry against further changes.
AltFormat lookupName(String name)
Returns the alt format that has been registered with the specified name.
AltFormat lookupType(ContentType contentType)
Returns the alt format that has been registered with the specified content type.
void register(AltFormat format, InputParser<?> parser, OutputGenerator<?> generator)
Registers the configuration for an AltFormat, replacing any existing configuration for the format in the registry.
Collection<AltFormat> registeredFormats()
Returns a collection of all registered formats in the registry.
void setDelegate(AltRegistry delegate)
Sets a delegate registry that will be used to satisfy lookups that cannot be resolved from the local registry.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private final Map<AltFormat, AltRegistry.AltHandlers> altHandlers

Contains a mapping from an alt format instance to the configuration for the format

private AltRegistry delegate

If non-null, contains a default registry that will be used as a delegate for all lookups that cannot be satisfied by this instance.

private boolean locked

If true, indicates that the registry is locked against further changes.

private final Map<String, AltFormat> nameMap

Contains a mapping from alt parameter name values to the associated format instance selected by each name.

private final Map<String, AltFormat> typeMap

Contains a mapping from alt parameter media type names to an alt format that represents the alternate content representation type selected by the media type.

Public Constructors

public AltRegistry ()

Constructs a new AltRegistry with no default registry configuration.

public AltRegistry (AltRegistry origRegistry)

Constructs a new AltRegistry with identical registration state to the provided registry. If the input value is null, a clean registry will be created.

Parameters
origRegistry Registry containing default configuration that will be used for lookups that can't be satisfied by the local registry.

Public Methods

public OutputGenerator<?> getGenerator (AltFormat altFormat)

Returns the OutputGenerator for the provided format or null if the format is not registered.

Parameters
altFormat Format to locate generator for.
Returns
  • generator for format or null.

public InputParser<?> getParser (AltFormat altFormat)

Returns the InputParser for a format or null if the format is not registered or does not support input parsing.

Parameters
altFormat Format to locate parser for.
Returns
  • parser for format or null.

public boolean hasSameHandlers (AltRegistry targetRegistry, AltFormat altFormat)

Returns true has an identical registration with the target registry for the specified alt format. Currently, this is only true if the copy constructor was used to do the initial registration and no subsequent changes have been made.

Parameters
targetRegistry Target registry to test
altFormat Alt format to test
Returns
  • true if registration for format is the same.

public void lock ()

Locks the registry against further changes. Any attempts to call the register(AltFormat, InputParser, OutputGenerator) API after lock has been called will fail.

public AltFormat lookupName (String name)

Returns the alt format that has been registered with the specified name.

Parameters
name Format name.
Returns
  • registered format matching the name or null.

public AltFormat lookupType (ContentType contentType)

Returns the alt format that has been registered with the specified content type.

Parameters
contentType Type to look up.
Returns
  • registered format matching the type or null.

public void register (AltFormat format, InputParser<?> parser, OutputGenerator<?> generator)

Registers the configuration for an AltFormat, replacing any existing configuration for the format in the registry.

Parameters
format Format to register
parser Input parser to use for the format (or null if not supported for input.
generator Output generator to use for the format.
Throws
IllegalStateException if registry has been locked.

public Collection<AltFormat> registeredFormats ()

Returns a collection of all registered formats in the registry. The collection does not include any values from the default registry provided at construction time.

Returns
  • collection of all registered alt formats.

public void setDelegate (AltRegistry delegate)

Sets a delegate registry that will be used to satisfy lookups that cannot be resolved from the local registry.

Parameters
delegate Delegate registry.