org.strutsme.wishlist.persistence.facade
Class AbstractWishlistPersistenceFacade

java.lang.Object
  extended by org.strutsme.wishlist.persistence.facade.AbstractWishlistPersistenceFacade
All Implemented Interfaces:
WishlistPersistenceFacade
Direct Known Subclasses:
WishlistPersistenceFacadeFake, WishlistPersistenceFacadeFile

public abstract class AbstractWishlistPersistenceFacade
extends java.lang.Object
implements WishlistPersistenceFacade


Field Summary
protected  int count
          Counter for create wishes.
protected  java.util.Map users
          Map of users.
protected  java.util.Map wishes
          Map of wishes.
 
Constructor Summary
AbstractWishlistPersistenceFacade()
          The constructor also loads the data or initilized it with some dummy data.
 
Method Summary
protected  void addDummyWishes()
          Add a certain amount of distinct dummy wishes.
 WishDto createWish()
          Creates a new wish.
 void deleteWish(java.lang.String wishId)
          Deletes an wish with this id.
protected  UserDto getDefaultUser()
          Gets the default user.
 UserDto getUserById(java.lang.String userId)
          Returns the user with this id.
 UserDto getUserByName(java.lang.String userName)
          Returns a user with this name.
 WishDto getWishById(java.lang.String wishId)
          Returns the wish with this id.
 java.util.List getWishes()
          Returns all wishes.
protected abstract  void load()
          Should load the data and update the instance variables.
 java.lang.String saveWish(WishDto wish)
          Saves an wish.
protected abstract  void stateChanged()
          Called if the state changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

count

protected int count
Counter for create wishes.


wishes

protected java.util.Map wishes
Map of wishes.


users

protected java.util.Map users
Map of users.

Constructor Detail

AbstractWishlistPersistenceFacade

public AbstractWishlistPersistenceFacade()
                                  throws java.io.IOException,
                                         java.lang.ClassNotFoundException
The constructor also loads the data or initilized it with some dummy data.

Throws:
java.lang.ClassNotFoundException - if the wishes couldn't be loaded
java.io.IOException - if the wishes couldn't be loaded
Method Detail

load

protected abstract void load()
                      throws java.io.IOException,
                             java.lang.ClassNotFoundException
Should load the data and update the instance variables.

Throws:
java.io.IOException - if the wishes couldn't be loaded
java.lang.ClassNotFoundException - if the wishes couldn't be loaded

getUserById

public final UserDto getUserById(java.lang.String userId)
Returns the user with this id.

Specified by:
getUserById in interface WishlistPersistenceFacade
Parameters:
userId - the id of user.
Returns:
a userDTO.

getUserByName

public final UserDto getUserByName(java.lang.String userName)
Returns a user with this name.

Specified by:
getUserByName in interface WishlistPersistenceFacade
Parameters:
userName - the name of user
Returns:
a userDTO

createWish

public final WishDto createWish()
Creates a new wish.

Specified by:
createWish in interface WishlistPersistenceFacade
Returns:
an wish

saveWish

public final java.lang.String saveWish(WishDto wish)
                                throws java.io.IOException
Saves an wish.

Specified by:
saveWish in interface WishlistPersistenceFacade
Parameters:
wish - the wish to save.
Returns:
the id of the saved wish.
Throws:
java.io.IOException - if the wish can't be saved.

stateChanged

protected abstract void stateChanged()
                              throws java.io.IOException
Called if the state changed. Can be used to save it.

Throws:
java.io.IOException - if for example the saving failed.

getWishById

public final WishDto getWishById(java.lang.String wishId)
                          throws java.io.IOException
Returns the wish with this id.

Specified by:
getWishById in interface WishlistPersistenceFacade
Parameters:
wishId - the id of the wish.
Returns:
an wishDto
Throws:
java.io.IOException - if the wish can't be accessed.

getWishes

public final java.util.List getWishes()
                               throws java.io.IOException
Returns all wishes.

Specified by:
getWishes in interface WishlistPersistenceFacade
Returns:
a list of wishes.
Throws:
java.io.IOException - if the wishes couldn't be loaded.

deleteWish

public final void deleteWish(java.lang.String wishId)
                      throws java.io.IOException
Deletes an wish with this id.

Specified by:
deleteWish in interface WishlistPersistenceFacade
Parameters:
wishId - the id of the wish to delete.
Throws:
java.io.IOException - if the wish can't be deleted.

getDefaultUser

protected final UserDto getDefaultUser()
Gets the default user. todo: Replace this method with a real user management.

Returns:
the default user.

addDummyWishes

protected final void addDummyWishes()
                             throws java.io.IOException
Add a certain amount of distinct dummy wishes.

Throws:
java.io.IOException - if the wishes couldn't be saved.