com.google.gdata.wireformats
Class AltRegistry

java.lang.Object
  extended by com.google.gdata.wireformats.AltRegistry

public class AltRegistry
extends java.lang.Object

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.


Constructor Summary
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.
 
Method Summary
 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(java.lang.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.
 java.util.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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AltRegistry

public AltRegistry()
Constructs a new AltRegistry with no default registry configuration.


AltRegistry

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.
Method Detail

register

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:
java.lang.IllegalStateException - if registry has been locked.

lock

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.


lookupName

public AltFormat lookupName(java.lang.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.

lookupType

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.

registeredFormats

public java.util.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.

getParser

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.

getGenerator

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.

setDelegate

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.

hasSameHandlers

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.