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);
}
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));
}
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));
}
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);
}
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) {
}
}
Aggregations