net.sourceforge.stripes.controller
Class UrlBindingFactory

java.lang.Object
  extended by net.sourceforge.stripes.controller.UrlBindingFactory

public class UrlBindingFactory
extends Object

Provides access to UrlBinding objects. Bindings are used in two contexts:

Since:
Stripes 1.5
Author:
Ben Gunter
See Also:
UrlBinding, UrlBindingParameter

Constructor Summary
protected UrlBindingFactory()
          Don't want the constructor to be public
 
Method Summary
 void addBinding(Class<? extends ActionBean> beanType, UrlBinding binding)
          Map an ActionBean to a URL.
protected  void cachePath(String path, UrlBinding binding)
          Map a path directly to a binding.
protected  void cachePrefix(String prefix, UrlBinding binding)
          Add a binding to the set of bindings associated with a prefix.
 Collection<Class<? extends ActionBean>> getActionBeanClasses()
          Get all the classes implementing ActionBean
 UrlBinding getBinding(HttpServletRequest request)
          Examines a servlet request and returns the associated binding, if any.
 UrlBinding getBinding(String uri)
          Examines a URI (as returned by HttpUtil.getRequestedPath(HttpServletRequest)) and returns the associated binding, if any.
 UrlBinding getBindingPrototype(Class<? extends ActionBean> type)
          Get the UrlBinding prototype associated with the given ActionBean type.
 UrlBinding getBindingPrototype(HttpServletRequest request)
          Examines a servlet request and returns the associated binding prototype, if any.
 UrlBinding getBindingPrototype(String uri)
          Examines a URI (as returned by HttpUtil.getRequestedPath(HttpServletRequest)) and returns the associated binding prototype, if any.
protected  Set<String> getCachedPaths(UrlBinding binding)
          Get a list of the request paths that will be wired directly to an ActionBean.
protected  Set<String> getCachedPrefixes(UrlBinding binding)
          Get a list of the request path prefixes that could map to an ActionBean.
static UrlBindingFactory getInstance()
          Get the singleton instance.
 HashMap<String,Class<? extends ActionBean>> getPathMap()
          Get all the ActionBeans classes that have been found.
static UrlBinding parseUrlBinding(Class<? extends ActionBean> beanType)
          Look for a binding pattern for the given ActionBean class, specified by the UrlBinding annotation.
static UrlBinding parseUrlBinding(Class<? extends ActionBean> beanType, String pattern)
          Parse the binding pattern and create a UrlBinding object for the ActionBean class.
static UrlBindingParameter parseUrlBindingParameter(Class<? extends ActionBean> beanClass, String string)
          Parses a parameter specification into name and default value and returns a UrlBindingParameter with the corresponding name and default value properties set accordingly.
 void removeBinding(Class<? extends ActionBean> beanType)
          Removes an ActionBean's URL binding.
 String toString()
           
protected  String trimContextPath(HttpServletRequest request)
          Deprecated. Use HttpUtil.getRequestedPath(HttpServletRequest) instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

UrlBindingFactory

protected UrlBindingFactory()
Don't want the constructor to be public

Method Detail

getInstance

public static UrlBindingFactory getInstance()
Get the singleton instance.

Returns:
an instance of this class

getActionBeanClasses

public Collection<Class<? extends ActionBean>> getActionBeanClasses()
Get all the classes implementing ActionBean


getBindingPrototype

public UrlBinding getBindingPrototype(Class<? extends ActionBean> type)
Get the UrlBinding prototype associated with the given ActionBean type. This method may return null if no binding is associated with the given type.

Parameters:
type - a class that implements ActionBean
Returns:
a binding object if one is defined or null if not

getBindingPrototype

public UrlBinding getBindingPrototype(String uri)
Examines a URI (as returned by HttpUtil.getRequestedPath(HttpServletRequest)) and returns the associated binding prototype, if any. No attempt is made to extract parameter values from the URI. This is intended as a fast means to get static information associated with a given request URI.

Parameters:
uri - a request URI
Returns:
a binding prototype, or null if the URI does not match

getBindingPrototype

public UrlBinding getBindingPrototype(HttpServletRequest request)
Examines a servlet request and returns the associated binding prototype, if any. No attempt is made to extract parameter values from the URI. This is intended as a fast means to get static information associated with a given request.

Parameters:
request - a servlet request
Returns:
a binding prototype, or null if the request URI does not match

getBinding

public UrlBinding getBinding(String uri)
Examines a URI (as returned by HttpUtil.getRequestedPath(HttpServletRequest)) and returns the associated binding, if any. Parameters will be extracted from the URI, and the UrlBindingParameter objects returned by UrlBinding.getParameters() will contain the values that are present in the URI.

Parameters:
uri - a request URI
Returns:
a binding prototype, or null if the URI does not match

getBinding

public UrlBinding getBinding(HttpServletRequest request)
Examines a servlet request and returns the associated binding, if any. Parameters will be extracted from the request, and the UrlBindingParameter objects returned by UrlBinding.getParameters() will contain the values that are present in the request.

Parameters:
request - a servlet request
Returns:
if the request matches a defined binding, then this method should return that binding. Otherwise, this method should return null.

getPathMap

public HashMap<String,Class<? extends ActionBean>> getPathMap()
Get all the ActionBeans classes that have been found.

Returns:
an immutable collection of ActionBean classes

addBinding

public void addBinding(Class<? extends ActionBean> beanType,
                       UrlBinding binding)
Map an ActionBean to a URL.

Parameters:
beanType - the ActionBean class
binding - the URL binding

removeBinding

public void removeBinding(Class<? extends ActionBean> beanType)
Removes an ActionBean's URL binding.

Parameters:
beanType - the ActionBean class

getCachedPaths

protected Set<String> getCachedPaths(UrlBinding binding)
Get a list of the request paths that will be wired directly to an ActionBean. In some cases, a single path might be valid for more than one ActionBean. In such a case, a warning will be logged at startup and an exception will be thrown if the conflicting path is requested.


getCachedPrefixes

protected Set<String> getCachedPrefixes(UrlBinding binding)
Get a list of the request path prefixes that could map to an ActionBean. A single prefix may map to multiple ActionBeans. In such a case, we attempt to determine the best match based on the literal strings and parameters defined in the ActionBeans' URL bindings. If no single ActionBean is determined to be a best match, then an exception is thrown to report the conflict.


cachePath

protected void cachePath(String path,
                         UrlBinding binding)
Map a path directly to a binding. If the path matches more than one binding, then a warning will be logged indicating such a condition, and the path will not be cached for any binding.

Parameters:
path - The path to cache
binding - The binding to which the path should map

cachePrefix

protected void cachePrefix(String prefix,
                           UrlBinding binding)
Add a binding to the set of bindings associated with a prefix.

Parameters:
prefix - The prefix to cache
binding - The binding to map to the prefix

parseUrlBinding

public static UrlBinding parseUrlBinding(Class<? extends ActionBean> beanType)
Look for a binding pattern for the given ActionBean class, specified by the UrlBinding annotation. If the annotation is found, create and return a UrlBinding object for the class. Otherwise, return null.

Parameters:
beanType - The ActionBean type whose binding is to be parsed
Returns:
A UrlBinding if one is specified, or null if not.
Throws:
ParseException - If the pattern cannot be parsed

parseUrlBinding

public static UrlBinding parseUrlBinding(Class<? extends ActionBean> beanType,
                                         String pattern)
Parse the binding pattern and create a UrlBinding object for the ActionBean class. If pattern is null or zero-length, then return null.

Parameters:
beanType - The ActionBean type to be mapped to the pattern.
pattern - The URL binding pattern to parse.
Returns:
A UrlBinding or null if the pattern is null or zero-length
Throws:
ParseException - If the pattern cannot be parsed

parseUrlBindingParameter

public static UrlBindingParameter parseUrlBindingParameter(Class<? extends ActionBean> beanClass,
                                                           String string)
Parses a parameter specification into name and default value and returns a UrlBindingParameter with the corresponding name and default value properties set accordingly.

Parameters:
beanClass - the bean class to which the binding applies
string - the parameter string
Returns:
a parameter object
Throws:
ParseException - if the pattern cannot be parsed

trimContextPath

@Deprecated
protected String trimContextPath(HttpServletRequest request)
Deprecated. Use HttpUtil.getRequestedPath(HttpServletRequest) instead.

Returns the URI of the given request with the context path trimmed from the beginning. I.e., the request URI relative to the context.

Parameters:
request - a servlet request
Returns:
the context-relative request URI

toString

public String toString()
Overrides:
toString in class Object


? Copyright 2005-2006, Stripes Development Team.