org.weborganic.berlioz.content
Class ServiceRegistry

java.lang.Object
  extended by org.weborganic.berlioz.content.ServiceRegistry

public final class ServiceRegistry
extends Object

A registry for services.

Note: this class is not synchronized and must be synchronized externally.

Since:
Berlioz 0.8
Version:
Berlioz 0.9.3 - 9 December 2011
Author:
Christophe Lauret

Constructor Summary
ServiceRegistry()
          Creates a new registry.
 
Method Summary
 List<String> allows(String url)
          Returns the list of HTTP methods allowed for this URL.
 void clear()
          Clears each generator mapping.
 MatchingService get(String url)
          Returns the list of content generators for this URL.
 MatchingService get(String url, HttpMethod method)
          Returns the content generator for this URL and HTTP method.
 MatchingService get(String url, String method)
          Returns the content generator for this URL and HTTP method.
 HttpMethod getMethod(Service service)
          Returns the HTTP method this service is mapped to.
 Map<String,Service> getServiceMap(HttpMethod method)
          Returns an unmodifiable map of services by URI Pattern for the specified HTTP method.
 List<Service> getServices()
          Returns the set of registered services.
 List<Service> getServices(HttpMethod method)
          Returns the list of services for the specified HTTP method.
 List<String> matches(Service service)
          Returns the list of URI Patterns that this service matches.
 void register(Service service, URIPattern pattern, HttpMethod method)
          Register the content generator.
 long version()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceRegistry

public ServiceRegistry()
Creates a new registry.

Method Detail

register

public void register(Service service,
                     URIPattern pattern,
                     HttpMethod method)
Register the content generator.

Parameters:
service - the service to register.
pattern - the URL pattern to associate to this content generator.
method - the method for this URL pattern.
Throws:
NullPointerException - If any argument is null

get

public MatchingService get(String url)
Returns the list of content generators for this URL.

This method iterates over each HTTP method in the following order: GET, POST, PUT, DELETE.

Parameters:
url - The URL.
Returns:
A content generator which URI pattern matches this URL or null.

allows

public List<String> allows(String url)
Returns the list of HTTP methods allowed for this URL.

If the GET method is supported, then the HEAD method is also supported and added to this list.

Parameters:
url - The URL.
Returns:
the list of HTTP methods allowed for this URL or an empty list.

getMethod

public HttpMethod getMethod(Service service)
Returns the HTTP method this service is mapped to.

Parameters:
service - The Berlioz service.
Returns:
the list of HTTP methods this Berlioz service is mapped to or null.

matches

public List<String> matches(Service service)
Returns the list of URI Patterns that this service matches.

Parameters:
service - The Berlioz service.
Returns:
the list of URI Patterns that this service matches or an empty list.

get

public MatchingService get(String url,
                           String method)
Returns the content generator for this URL and HTTP method.

If the HTTP method specified is HEAD, this method will return the service for a GET request.

Parameters:
url - The URL.
method - The HTTP method.
Returns:
A content generator which URI pattern matches this URL and HTTP method or null.

get

public MatchingService get(String url,
                           HttpMethod method)
Returns the content generator for this URL and HTTP method.

If the HTTP method specified is HEAD, this method will return the service for a GET request.

Parameters:
url - The URL.
method - The HTTP method.
Returns:
A content generator which URI pattern matches this URL and HTTP method or null.

getServiceMap

public Map<String,Service> getServiceMap(HttpMethod method)
Returns an unmodifiable map of services by URI Pattern for the specified HTTP method.

Parameters:
method - the HTTP method.
Returns:
an unmodifiable map of services by URI Pattern

getServices

public List<Service> getServices()
Returns the set of registered services.

Returns:
the set of registered services.

getServices

public List<Service> getServices(HttpMethod method)
Returns the list of services for the specified HTTP method.

Parameters:
method - the HTTP method.
Returns:
the list of services.

clear

public void clear()
Clears each generator mapping.


version

public long version()
Returns:
The version of this registry.