/**
* @see org.andromda.metafacades.uml.OperationFacade#getExceptions()
*/
protected Collection handleGetExceptions()
{
Collection exceptions = new LinkedHashSet();
// finds both exceptions and exception references
final class ExceptionFilter
implements Predicate
{
public boolean evaluate(Object object)
{
boolean hasException = object instanceof DependencyFacade;
if (hasException)
{
DependencyFacade dependency = (DependencyFacade)object;
// first check for exception references
hasException = dependency.hasStereotype(UMLProfile.STEREOTYPE_EXCEPTION_REF);
// if there wasn't any exception reference
// now check for actual exceptions
if (!hasException)
{
ModelElementFacade targetElement = dependency.getTargetElement();
hasException = targetElement != null && targetElement.hasStereotype(
UMLProfile.STEREOTYPE_EXCEPTION);
}
}
return hasException;
}
}
// first get any dependencies on this operation's
// owner (because these will represent the default exception(s))
final Collection ownerDependencies = new ArrayList(this.getOwner().getSourceDependencies());
if (ownerDependencies != null && !ownerDependencies.isEmpty())
{
CollectionUtils.filter(ownerDependencies, new ExceptionFilter());
exceptions.addAll(ownerDependencies);
}
final Collection operationDependencies = new ArrayList(this.getSourceDependencies());
// now get any exceptions directly on the operation
if (operationDependencies != null && !operationDependencies.isEmpty())
{
CollectionUtils.filter(operationDependencies, new ExceptionFilter());
exceptions.addAll(operationDependencies);
}
// now transform the dependency(s) to the actual exception(s)
CollectionUtils.transform(exceptions, new Transformer()
{
public Object transform(Object object)
{
return ((DependencyFacade)object).getTargetElement();
}
});
// finally add in any members of the UML2 RaisedException list
// (the 'proper' UML2 way of doing exceptions .. or at least one way).
Collection raisedExceptions = this.metaObject.getRaisedExceptions();
exceptions.addAll(this.shieldedElements(raisedExceptions));
return exceptions;
}