/*
BERSERK - a BusinEss Runtime and SEcurity Resources Kit
Copyright (C) 2003 Goncalo Luiz
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact Goncalo Luiz use the following e-mail address (use an @ instead of the _):
gedl_mega.ist.utl.pt
*/
package pt.utl.ist.berserk.logic.serviceManager;
/**
* @author Jorge Martins
* @version revision by Goncalo Luiz (gedl \AT/ rnl \DOT/ ist \DOT/ utl \DOT/ pt) at June the 15th, 2004
**/
import pt.utl.ist.berserk.BerserkConfiguration;
import pt.utl.ist.berserk.ServiceRequest;
import pt.utl.ist.berserk.ServiceResponse;
import pt.utl.ist.berserk.logic.filterManager.FilteringResult;
import pt.utl.ist.berserk.logic.filterManager.IFilterBroker;
import pt.utl.ist.berserk.logic.serviceManager.exceptions.ExecutedFilterException;
import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException;
import pt.utl.ist.berserk.logic.serviceManager.exceptions.ServiceManagerException;
import pt.utl.ist.berserk.storage.ITransactionBroker;
import pt.utl.ist.berserk.storage.exceptions.StorageException;
public class TransactionalServiceInvoker
extends ServiceInvoker
{
public final static TransactionalServiceInvoker invocador =
new TransactionalServiceInvoker
();
public final 5+0%2Fdocs%2Fapi+Object">Object invoke
(
5+0%2Fdocs%2Fapi+Object">Object requester,
IService service,
1.5.0/docs/api/java/lang/String.html">String methodName,
5+0%2Fdocs%2Fapi+Object">Object arguments
[],
1.5.0/docs/api/java/lang/String.html">String names
[],
IFilterBroker broker
)
throws ServiceManagerException,
1.5.0/docs/api/java/lang/Throwable.html">Throwable
{
boolean passedPre =
false;
boolean passedPost =
false;
ServiceRequest request =
new ServiceRequest
(requester, arguments,names,service,methodName
);
ServiceResponse response =
new ServiceResponse
();
FilteringResult filteringResult =
null;
ITransactionBroker tb = BerserkConfiguration.
getApplicationTransactionBroker();
try
{
tb.
beginTransaction();
try
{
filteringResult = broker.
executePreFiltering(request, response
);
passedPre = filteringResult.
isSuccess();
}
catch (1.5.0/docs/api/java/lang/Exception.html">Exception e
)
{
throw new ExecutedFilterException
(
"a not 'FilterException' exception occured while executing pre filter chain",
e
);
}
if (passedPre
)
{
response.
setReturnObject(doInvocation
(request.
getService(), methodName, request.
getArguments()));
}
else
{
throw new FilterChainFailedException
(
"failed to execute postFiltering on service" + service.
getClass(),filteringResult
);
}
try
{
filteringResult = broker.
executePostFiltering(request, response
);
passedPost = filteringResult.
isSuccess();
}
catch (1.5.0/docs/api/java/lang/Exception.html">Exception e
)
{
throw new ExecutedFilterException
(
"a not 'FilterException' exception occured while executing pre filter chain",
e
);
}
if (passedPost
)
{
//the sucessfull case
tb.
commitTransaction();
return response.
getReturnObject();
}
else
{
throw new FilterChainFailedException
(
"failed to execute postFiltering on service" + service.
getClass(),filteringResult
);
}
}
catch (FilterChainFailedException ex
)
{
//ok let this exception go up
try
{
//if we get here, something went wrong with the executing service. we should roll back all changes
tb.
abortTransaction();
}
catch (StorageException e
)
{
throw new ServiceManagerException
("Storage Exception while aborting transaction",e
);
}
throw ex
;
}
catch (ExecutedFilterException ex
)
{
//ok let this exception go up
try
{
//if we get here, something went wrong with the executing service. we should roll back all changes
tb.
abortTransaction();
}
catch (StorageException e
)
{
throw new ServiceManagerException
("Storage Exception while aborting transaction",e
);
}
throw ex
;
}
catch (StorageException ex
)
{
try
{
//if we get here, something went wrong with the executing service. we should roll back all changes
tb.
abortTransaction();
}
catch (StorageException e
)
{
throw new ServiceManagerException
("Storage Exception while aborting transaction",e
);
}
throw new ServiceManagerException
("Storage exception while executing transactional service",ex
);
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable ex
)
{
//ok let this exception go up
try
{
//if we get here, something went wrong with the executing service. we should roll back all changes
tb.
abortTransaction();
}
catch (StorageException e
)
{
throw new ServiceManagerException
("Storage Exception while aborting transaction",e
);
}
throw ex
;
}
}
}