Search in sources :

Example 1 with DataKinds

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;
}
Also used : WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 2 with DataKinds

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;
}
Also used : DataKinds(org.whole.lang.reflect.DataKinds)

Example 3 with DataKinds

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);
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) DataKinds(org.whole.lang.reflect.DataKinds)

Example 4 with DataKinds

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()));
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Example 5 with DataKinds

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())));
}
Also used : IEntity(org.whole.lang.model.IEntity) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) DataKinds(org.whole.lang.reflect.DataKinds)

Aggregations

DataKinds (org.whole.lang.reflect.DataKinds)22 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)17 IEntity (org.whole.lang.model.IEntity)12 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)3 ArrayList (java.util.ArrayList)1 EnumValue (org.whole.lang.model.EnumValue)1