public Class<? extends GenericValue> validateTypes(final GenericValue parentExpr,
final boolean allowCollections) throws HBqlException {
if (this.getTypedExpr() == null && this.getTypedExprList() == null)
throw new InvalidTypeException("Parameter \"" + this.getParamName() + "\" not assigned a value");
if (this.isScalarValueSet()) {
return this.getTypedExpr().getClass();
}
else {
// Make sure a list is legal in this expr
if (!allowCollections) {
final String context = parentExpr == null ? "" : " in the context " + parentExpr.asString();
throw new InvalidTypeException("Parameter " + this.getParamName()
+ " is assigned a collection which is not allowed" + context);
}
// if it is a list, then ensure that all the types in list are valid and consistent
if (this.getTypedExprList().size() == 0)
throw new InvalidTypeException("Parameter " + this.getParamName() + " is assigned a collection with no values");
// Look at the type of the first item and then make sure the rest match that one
final GenericValue firstval = this.getTypedExprList().get(0);
final Class<? extends GenericValue> clazzToMatch = TypeSupport.getGenericExprType(firstval);
for (final GenericValue val : this.getTypedExprList()) {
final Class<? extends GenericValue> clazz = TypeSupport.getGenericExprType(val);
if (clazz == null)
throw new InvalidTypeException("Parameter " + this.getParamName()
+ " assigned a collection value with invalid type "
+ firstval.getClass().getSimpleName());
if (!clazz.equals(clazzToMatch))
throw new InvalidTypeException("Parameter " + this.getParamName()
+ " assigned a collection value with type "
+ firstval.getClass().getSimpleName()
+ " which is inconsistent with the type of the first element");
}