use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class DataTypeUtils method getMostSpecificDescriptor.
public static EntityDescriptor<?> getMostSpecificDescriptor(EntityDescriptor<?> ed, String value, DataTypeParsers parserKind) {
if (!ed.getDataKind().isNotAData())
return ed;
EntityDescriptor<?> msed = ed;
int specificity = DataKinds.NOT_A_DATA.ordinal();
for (EntityDescriptor<?> sed : ed.getLanguageConcreteSubtypes()) {
final DataKinds dataKind = sed.getDataKind();
if (dataKind.ordinal() < specificity) {
try {
getDataTypeParser(sed, parserKind).parse(sed, value);
msed = sed;
specificity = dataKind.ordinal();
} catch (IllegalArgumentException e) {
}
}
}
return msed;
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class DataTypeUtils method getUnboxedDataKind.
public static final DataKinds getUnboxedDataKind(IEntity entity) {
EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
DataKinds dataKind = ed.getDataKind();
if (dataKind.isObject())
return toUnboxedDataKind(ed.getDataType());
else
return dataKind;
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class XsiModelTemplate method toContentValue.
protected String toContentValue(IEntity entity, IMappingStrategy strategy) {
EntityDescriptor<?> ed = entity.wGetEntityDescriptor();
DataKinds dataKind = ed.getDataKind();
if (!dataKind.isNotAData()) {
IDataTypeParser dataTypeParser = ed.getLanguageKit().getDataTypeParser(DataTypeParsers.PERSISTENCE);
switch(dataKind) {
case BOOLEAN:
return dataTypeParser.unparseBoolean(ed, entity.wBooleanValue());
case BYTE:
return dataTypeParser.unparseByte(ed, entity.wByteValue());
case SHORT:
return dataTypeParser.unparseShort(ed, entity.wShortValue());
case INT:
return dataTypeParser.unparseInt(ed, entity.wIntValue());
case LONG:
return dataTypeParser.unparseLong(ed, entity.wLongValue());
case DOUBLE:
return dataTypeParser.unparseDouble(ed, entity.wDoubleValue());
case FLOAT:
return dataTypeParser.unparseFloat(ed, entity.wFloatValue());
case STRING:
return dataTypeParser.unparseString(ed, entity.wStringValue());
case OBJECT:
return dataTypeParser.unparseObject(ed, entity.wGetValue());
case ENUM_VALUE:
return dataTypeParser.unparseEnumValue(ed, entity.wEnumValue());
case DATE:
case CHAR:
}
}
throw new IllegalStateException(WholeMessages.no_data_type);
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class MathInterpreterVisitor method visit.
@Override
public void visit(Not entity) {
IEntity result = evaluate(entity.getExpression());
DataKinds dataKinds = DataTypeUtils.getUnboxedDataKind(result);
if (dataKinds.isNotAData())
throw new WholeIllegalArgumentException(WholeMessages.no_data).withSourceEntity(entity).withBindings(getBindings());
else if (!dataKinds.isBoolean())
throw new WholeIllegalArgumentException(WholeMessages.illegal_data_conversion).withSourceEntity(entity).withBindings(getBindings());
else
setResult(createBooleanLiteral(!result.wBooleanValue()));
}
use of org.whole.lang.reflect.DataKinds in project whole by wholeplatform.
the class MathInterpreterVisitor method visit.
@Override
public void visit(Implies entity) {
IEntity result1 = evaluate(entity.getExp1());
IEntity result2 = evaluate(entity.getExp2());
DataKinds dataKind1 = DataTypeUtils.getUnboxedDataKind(result1);
DataKinds dataKind2 = DataTypeUtils.getUnboxedDataKind(result2);
if (dataKind1.isNotAData() || dataKind2.isNotAData())
throw new WholeIllegalArgumentException(WholeMessages.no_data).withSourceEntity(entity).withBindings(getBindings());
else if (!dataKind1.isBoolean() || !dataKind2.isBoolean())
throw new WholeIllegalArgumentException(WholeMessages.illegal_data_conversion).withSourceEntity(entity).withBindings(getBindings());
else
setResult(createBooleanLiteral(!(result1.wBooleanValue() && !result2.wBooleanValue())));
}
Aggregations