Project

Profile

Help

RE: Migration from Saxon6.5.3 to Saxon 9.x ยป CheckAvailabilityElement.java

mandar nimbkar, 2014-05-21 12:54

 
import com.icl.saxon.Context;
import com.icl.saxon.expr.Expression;
import com.icl.saxon.style.StyleElement;


public class CheckAvailabilityElement extends StyleElement
{

//some other methods//

public void process(final Context aContext) throws BusinessException
{
boolean result = true;
final String availabilityString =
evaluateExpressionAsString(this.availability, aContext, false);
// some additional logic
}


protected String evaluateExpressionAsString(
final Expression anExpression, final Context aContext, final boolean isRequired)
throws BusinessException
{
//---------------------------------------------------------------------------
// The expression may be null if and only if optional flag has been specified
//---------------------------------------------------------------------------
if (anExpression == null)
{
if (isRequired)
{
final String message = "Null expression is not allowed";
//If the expression is null, then throw error
final BusinessException exception = styleError(message);
throw exception;
}
else
{
return null;
}
}


//------------------------
// Evaluate the expression
//------------------------
final String result;
try
{
result = anExpression.evaluateAsString(aContext);
}
catch (final XPathException anException)
{
final String message = "Error evaluating expression";
throw new BusinessException(message, this, anException);
}


//--------------------------------
// Check for empty or null results
//--------------------------------
if ((result == null) || (result.length()) == 0)
{
if (isRequired)
{
final String message =
"Required expression evaluated to an empty value: " + anExpression.toString();
final BusinessException exception = styleError(message);
throw exception;
}
else
{
return null;
}
}

return result;
}

//some other methods//

}
    (1-1/1)