Search in sources :

Example 1 with QueryProfileFieldType

use of com.yahoo.search.query.profile.types.QueryProfileFieldType in project vespa by vespa-engine.

the class QueryProfile method checkAndConvertAssignment.

/**
 * Converts to the type of the receiving field, if possible and necessary.
 *
 * @return the value to be assigned: the original or a converted value
 * @throws IllegalArgumentException if the assignment is illegal
 */
protected Object checkAndConvertAssignment(String localName, Object value, QueryProfileRegistry registry) {
    // no type checking
    if (type == null)
        return value;
    FieldDescription fieldDescription = type.getField(localName);
    if (fieldDescription == null) {
        if (type.isStrict())
            throw new IllegalArgumentException("'" + localName + "' is not declared in " + type + ", and the type is strict");
        return value;
    }
    if (registry == null && (fieldDescription.getType() instanceof QueryProfileFieldType))
        throw new IllegalArgumentException("A registry was not passed: Query profile references is not supported");
    Object convertedValue = fieldDescription.getType().convertFrom(value, registry);
    if (convertedValue == null)
        throw new IllegalArgumentException("'" + value + "' is not a " + fieldDescription.getType().toInstanceDescription());
    return convertedValue;
}
Also used : FieldDescription(com.yahoo.search.query.profile.types.FieldDescription) QueryProfileFieldType(com.yahoo.search.query.profile.types.QueryProfileFieldType)

Aggregations

FieldDescription (com.yahoo.search.query.profile.types.FieldDescription)1 QueryProfileFieldType (com.yahoo.search.query.profile.types.QueryProfileFieldType)1