Search in sources :

Example 1 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class DataTypeUtils method buildFromPresentationString.

public static void buildFromPresentationString(IBuilder builder, EntityDescriptor<?> ed, String value) {
    IDataTypeParser parser = getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
    buildFromString(builder, ed, value, parser);
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser)

Example 2 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class DataTypeUtils method createFromPersistenceString.

public static IEntity createFromPersistenceString(EntityDescriptor<?> ed, String data) {
    IDataTypeParser parser = getDataTypeParser(ed, DataTypeParsers.PERSISTENCE);
    ed = getMostSpecificDescriptor(ed, data, DataTypeParsers.PERSISTENCE);
    return GenericEntityFactory.instance.create(ed, parser.parse(ed, data));
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser)

Example 3 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class DataTypeUtils method createFromPresentationString.

public static IEntity createFromPresentationString(EntityDescriptor<?> ed, String data) {
    IDataTypeParser parser = getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
    ed = getMostSpecificDescriptor(ed, data, DataTypeParsers.PRESENTATION);
    return GenericEntityFactory.instance.create(ed, parser.parse(ed, data));
}
Also used : IDataTypeParser(org.whole.lang.parsers.IDataTypeParser)

Example 4 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser 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 5 with IDataTypeParser

use of org.whole.lang.parsers.IDataTypeParser in project whole by wholeplatform.

the class DataTypeUtilsTest method testByteData.

@Test
public void testByteData() {
    TestEntitiesEntityFactory ef = TestEntitiesEntityFactory.instance;
    IEntity e = ef.createByteTestEntity((byte) 27);
    assertGenericParseUnparseRoundtrip(e, "32");
    assertEquals("27", DataTypeUtils.getAsPresentationString(e));
    assertEquals("27", DataTypeUtils.getAsPersistenceString(e));
    DataTypeUtils.setFromPresentationString(e, "35");
    assertEquals((byte) 35, e.wByteValue());
    DataTypeUtils.setFromPersistenceString(e, "56");
    assertEquals((byte) 56, e.wByteValue());
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Byte.MIN_VALUE));
    assertEquals(Byte.MIN_VALUE, e.wByteValue());
    DataTypeUtils.setFromPresentationString(e, String.valueOf(Byte.MAX_VALUE));
    assertEquals(Byte.MAX_VALUE, e.wByteValue());
    e = DataTypeUtils.createFromPresentationString(TestEntitiesEntityDescriptorEnum.ByteTestEntity, "18");
    assertEquals((byte) 18, e.wByteValue());
    e = DataTypeUtils.createFromPersistenceString(TestEntitiesEntityDescriptorEnum.ByteTestEntity, "76");
    assertEquals((byte) 76, e.wByteValue());
    final EntityDescriptor<?> ed = e.wGetEntityDescriptor();
    IDataTypeParser parser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
    try {
        parser.parseByte(ed, "string");
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        parser.parseByte(ed, "200");
        fail();
    } catch (IllegalArgumentException iae) {
    }
    try {
        parser.parseByte(ed, "2.5f");
        fail();
    } catch (IllegalArgumentException iae) {
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) TestEntitiesEntityFactory(org.whole.lang.testentities.factories.TestEntitiesEntityFactory) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) Test(org.junit.Test)

Aggregations

IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)32 Test (org.junit.Test)18 IEntity (org.whole.lang.model.IEntity)12 TestEntitiesEntityFactory (org.whole.lang.testentities.factories.TestEntitiesEntityFactory)10 DataKinds (org.whole.lang.reflect.DataKinds)3 ILanguageKit (org.whole.lang.reflect.ILanguageKit)3 SchemaDataTypeParsers.normalizedString (org.whole.lang.xsd.parsers.SchemaDataTypeParsers.normalizedString)3 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 Grammar (org.whole.lang.grammars.model.Grammar)1 EnumValue (org.whole.lang.model.EnumValue)1 IOperation (org.whole.lang.operations.IOperation)1 ForwardEntityDescriptorStrategyDataTypeParser (org.whole.lang.parsers.ForwardEntityDescriptorStrategyDataTypeParser)1 AbstractLanguageExtensionDeployer (org.whole.lang.reflect.AbstractLanguageExtensionDeployer)1 DynamicLanguageKit (org.whole.lang.reflect.DynamicLanguageKit)1 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)1 EntityDescriptorEnum (org.whole.lang.reflect.EntityDescriptorEnum)1