telosys
Blame | Last modification | View Log | RSS feed
package org.objectweb.telosys.dal.rest;
/**
* DAO REST response object <br>
*
* @author Olivier Laurendeau, Laurent GUERIN
* @since 1.0.0
*/
/* package */ class DAOResponse
{
private Class _daoClass = null ;
private String _sAction = null ;
private Boolean _bRetCode = null ;
private Long _lRetCode = null ;
private Object _oResult = null ;
private Boolean _bFound = null ;
/**
* Constructor for a response with a boolean return code ( for "exists" action )
* @param cl
* @param action
* @param b return code
*/
public DAOResponse(Class cl, String action, boolean b )
{
_daoClass = cl ;
_sAction = action;
//_bRetCode = new Boolean(b);
_bRetCode = Boolean.valueOf(b);
}
/**
* Constructor for a response with a Long return code ( for "insertkeygen" action )
* @param cl
* @param action
* @param l return code
*/
public DAOResponse(Class cl, String action, Long l )
{
_daoClass = cl ;
_sAction = action;
_lRetCode = l;
}
/**
* Constructor for a response with an integer return code ( for classical actions "insert", "delete", "update", "save" )
* @param cl
* @param action
* @param i return code
*/
public DAOResponse(Class cl, String action, int i )
{
_daoClass = cl ;
_sAction = action;
_lRetCode = new Long(i);
}
/**
* Constructor for a response with an integer return code and an object to render ( for "loadlist" action )
* @param cl
* @param action
* @param i return code
* @param bean object to render
*/
public DAOResponse(Class cl, String action, int i, Object bean )
{
_daoClass = cl ;
_sAction = action;
_lRetCode = new Long(i);
_oResult = bean ;
}
/**
* Constructor for a response with an integer return code, an object to render and a found flag ( for "load" action )
* @param cl
* @param action
* @param i return code
* @param bean object to render
* @param found "found" flag
*/
public DAOResponse(Class cl, String action, int i, Object bean, boolean found )
{
_daoClass = cl ;
_sAction = action;
_lRetCode = new Long(i);
if ( found ) {
_oResult = bean ;
}
//_bFound = new Boolean(found); ;
_bFound = Boolean.valueOf(found);
}
/**
* @return the class of the DAO
*/
public Class getDAOClass()
{
return _daoClass ;
}
/**
* @return the class name of the DAO
*/
public String getDAOClassName()
{
return ( _daoClass != null ? _daoClass.getName() : "null" ) ;
}
/**
* @return the action ( "load", "save", ... )
*/
public String getAction()
{
return _sAction;
}
/**
* @return the return code as a string : boolean "true"/"false" or integer "1","1222",... or "null"
*/
public String getRetCode()
{
String s = "null" ;
if ( _bRetCode != null )
{
s = "" + _bRetCode.booleanValue();
}
if ( _lRetCode != null )
{
s = "" + _lRetCode.longValue();
}
return s ;
}
// public Boolean getBoolRetCode()
// {
// return _bRetCode;
// }
//
// public Long getLongRetCode()
// {
// return _lRetCode;
// }
/**
* @return the result object of the action
*/
public Object getResultObject()
{
return _oResult;
}
/**
* @return true if flag "found" set and true, else false
*/
public boolean isFound()
{
if ( _bFound != null ) return _bFound.booleanValue() ;
return false ;
}
/**
* @return true if flag "found" set and false, else false
*/
public boolean isNotFound()
{
if ( _bFound != null ) return ( ! _bFound.booleanValue() ) ;
return false ;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
String s = _oResult != null ? _oResult.getClass().getName() : "null" ;
return _sAction + " : return code = " + getRetCode() + " ( result : " + s + " )" ;
}
}