com.octo.captcha.service.captchastore
Class MapCaptchaStore

java.lang.Object
  extended by com.octo.captcha.service.captchastore.MapCaptchaStore
All Implemented Interfaces:
CaptchaStore
Direct Known Subclasses:
FastHashMapCaptchaStore

public class MapCaptchaStore
extends java.lang.Object
implements CaptchaStore

Simple store based on a HashMap


Constructor Summary
MapCaptchaStore()
           
 
Method Summary
 void cleanAndShutdown()
          Called by the service in order to clean and shutdown the store.
 void empty()
          Empty the store
 Captcha getCaptcha(java.lang.String id)
          Retrieve the captcha for this key from the store.
 java.util.Collection getKeys()
          Return all the contained keys
 java.util.Locale getLocale(java.lang.String id)
          Retrieve the locale for this key from the store.
 int getSize()
          get the size of this store
 boolean hasCaptcha(java.lang.String id)
          Check if a captcha is stored for this id
 void initAndStart()
          Called by the service in order to initialize and start the Store.
 boolean removeCaptcha(java.lang.String id)
          Remove the captcha with the provided id as key.
 void storeCaptcha(java.lang.String id, Captcha captcha)
          Store the captcha with the provided id as key.
 void storeCaptcha(java.lang.String id, Captcha captcha, java.util.Locale locale)
          Store the captcha with the provided id as key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapCaptchaStore

public MapCaptchaStore()
Method Detail

hasCaptcha

public boolean hasCaptcha(java.lang.String id)
Check if a captcha is stored for this id

Specified by:
hasCaptcha in interface CaptchaStore
Returns:
true if a captcha for this id is stored, false otherwise

storeCaptcha

public void storeCaptcha(java.lang.String id,
                         Captcha captcha)
                  throws CaptchaServiceException
Store the captcha with the provided id as key. The key is assumed to be unique, so if the same key is used twice to store a captcha, the store will return an exception

Specified by:
storeCaptcha in interface CaptchaStore
Parameters:
id - the key
captcha - the captcha
Throws:
CaptchaServiceException - if the captcha already exists, or if an error occurs during storing routine.

storeCaptcha

public void storeCaptcha(java.lang.String id,
                         Captcha captcha,
                         java.util.Locale locale)
                  throws CaptchaServiceException
Store the captcha with the provided id as key. The key is assumed to be unique, so if the same key is used twice to store a captcha, the store will return an exception

Specified by:
storeCaptcha in interface CaptchaStore
Parameters:
id - the key
captcha - the captcha
locale - the locale used that triggers the captcha generation
Throws:
CaptchaServiceException - if the captcha already exists, or if an error occurs during storing routine.

getCaptcha

public Captcha getCaptcha(java.lang.String id)
                   throws CaptchaServiceException
Retrieve the captcha for this key from the store.

Specified by:
getCaptcha in interface CaptchaStore
Returns:
the captcha for this id
Throws:
CaptchaServiceException - if a captcha for this key is not found or if an error occurs during retrieving routine.

getLocale

public java.util.Locale getLocale(java.lang.String id)
                           throws CaptchaServiceException
Retrieve the locale for this key from the store.

Specified by:
getLocale in interface CaptchaStore
Returns:
the locale for this id, null if not found
Throws:
CaptchaServiceException - if an error occurs during retrieving routine.

removeCaptcha

public boolean removeCaptcha(java.lang.String id)
Remove the captcha with the provided id as key.

Specified by:
removeCaptcha in interface CaptchaStore
Parameters:
id - the key
Returns:
true if found, false otherwise
Throws:
CaptchaServiceException - if an error occurs during remove routine

getSize

public int getSize()
get the size of this store

Specified by:
getSize in interface CaptchaStore

getKeys

public java.util.Collection getKeys()
Return all the contained keys

Specified by:
getKeys in interface CaptchaStore

empty

public void empty()
Empty the store

Specified by:
empty in interface CaptchaStore

initAndStart

public void initAndStart()
Description copied from interface: CaptchaStore
Called by the service in order to initialize and start the Store.

Specified by:
initAndStart in interface CaptchaStore

cleanAndShutdown

public void cleanAndShutdown()
Description copied from interface: CaptchaStore
Called by the service in order to clean and shutdown the store.

Specified by:
cleanAndShutdown in interface CaptchaStore


Copyright 2003-2009 JCaptcha. All Rights Reserved.