{
return valueType.cast(this);
}
else if (getValueType() == ModelValueType.UNDEFINED)
{
ModelValue mv;
if (ModelReference.class.isAssignableFrom(valueType))
{
mv = new DmrModelReference(value);
}
else if (ModelObject.class.isAssignableFrom(valueType))
{
mv = new DmrModelObject(value);
}
else if (ModelList.class.isAssignableFrom(valueType))
{
mv = new DmrModelList(value);
}
else if (ModelString.class.isAssignableFrom(valueType))
{
mv = new DmrModelString(value);
}
else if (ModelNumber.class.isAssignableFrom(valueType))
{
mv = new DmrModelNumber(value);
}
else if (ModelBoolean.class.isAssignableFrom(valueType))
{
mv = new DmrModelBoolean(value);
}
else
{
throw new IllegalArgumentException("No mapping defined for ModelValue type " + valueType);
}
return valueType.cast(mv);
}
else
{
ModelValue value = asValue(this.value);
try
{
return valueType.cast(value);
}
catch (ClassCastException e)
{
throw new IllegalArgumentException("ModelValue type is " + value.getValueType() + " and cannot be cast to " + valueType.getName());
}
}
}