use of org.whole.lang.model.EnumValue in project whole by wholeplatform.
the class BindingManagerTest method testBindData.
@Test
public void testBindData() {
bm.wDefValue("bool", false);
assertTrue(bm.wBooleanValue("bool") == false);
bm.wDefValue("byte", (byte) 4);
assertTrue(bm.wByteValue("byte") == 4);
bm.wDefValue("char", 'c');
assertTrue(bm.wCharValue("char") == 'c');
bm.wDefValue("double", 3.5d);
assertTrue(bm.wDoubleValue("double") == 3.5d);
bm.wDefValue("float", 1.25f);
assertTrue(bm.wFloatValue("float") == 1.25f);
bm.wDefValue("int", 12);
assertTrue(bm.wIntValue("int") == 12);
bm.wDefValue("long", 324l);
assertTrue(bm.wLongValue("long") == 324l);
bm.wDefValue("short", (short) 34);
assertTrue(bm.wShortValue("short") == 34);
bm.wDefValue("string", "abc");
assertEquals("abc", bm.wStringValue("string"));
Date d = new Date();
bm.wDefValue("date", d);
assertSame(d, bm.wDateValue("date"));
EnumValue e = FeatureModifierEnum.optional;
bm.wDefValue("enum", e);
assertEquals(e, bm.wEnumValue("enum"));
Object o = new Object();
bm.wDefValue("object", o);
assertSame(o, bm.wGetValue("object"));
}
use of org.whole.lang.model.EnumValue in project whole by wholeplatform.
the class PojoUtils method create.
@SuppressWarnings("unchecked")
public static <E extends IEntity> E create(Object fromObject, Type type, Library library) {
// map product type
ProductDeclaration productDeclaration = findProductDeclaration(type, library);
E toIEntity = PojoUtils.<E>createEntity(productDeclaration, library);
// translate contents as needed
switch(productDeclaration.wGetEntityDescriptor().getOrdinal()) {
case PojoDeclaration_ord:
translate(fromObject, toIEntity, (PojoDeclaration) productDeclaration, library);
break;
case EnumDeclaration_ord:
EnumValue enumValue = DefaultDataTypePersistenceParser.instance.parseEnumValue(toIEntity.wGetEntityDescriptor(), fromObject.toString());
toIEntity.wSetValue(enumValue);
break;
case // TODO
AnnotationDeclaration_ord:
break;
case DataTypeDeclaration_ord:
Type elementType;
switch(type.wGetEntityDescriptor().getOrdinal()) {
case PrimitiveType_ord:
case ReferenceType_ord:
toIEntity.wSetValue(fromObject);
break;
case ArrayType_ord:
ArrayType arrayType = (ArrayType) type;
elementType = arrayType.getElementType();
for (int i = 0; i < Array.getLength(fromObject); i++) toIEntity.wAdd(create(Array.get(fromObject, i), elementType, library));
break;
case CollectionType_ord:
CollectionType collectionType = (CollectionType) type;
Collection<Object> fromCollection = (Collection<Object>) fromObject;
elementType = collectionType.getElementType();
for (Object element : fromCollection) toIEntity.wAdd(create(element, elementType, library));
break;
case MapType_ord:
MapType mapType = (MapType) type;
Map<Object, Object> fromMap = (Map<Object, Object>) fromObject;
Type keyType = mapType.getKeyType();
elementType = mapType.getValueType();
for (Entry<Object, Object> element : fromMap.entrySet()) // FIXME workaround for Java 8 compiler
toIEntity.wSet(// FIXME workaround for Java 8 compiler
(IEntity) create(element.getKey(), keyType, library), create(element.getValue(), elementType, library));
break;
}
break;
}
return toIEntity;
}
use of org.whole.lang.model.EnumValue in project whole by wholeplatform.
the class ContentAssistOperation method visit.
@Override
public void visit(IEntity entity) {
EntityDescriptor<?> entityEd = entity.wGetEntityDescriptor();
DataKinds dataKind = entityEd.getDataKind();
// TODO merge with parent results if different language
if (dataKind.isNotAData()) {
IEntity parent = entity.wGetParent();
if (!EntityUtils.isNull(parent)) {
entityEd = parent.wGetEntityDescriptor(entity);
dataKind = entityEd.getDataKind();
}
}
final EntityDescriptor<?> ed = entityEd;
switch(dataKind) {
case ENUM_VALUE:
final List<EnumValue> enumValues = new ArrayList<EnumValue>(ed.getDataEnumType().values());
final IDataTypeParser unparser = DataTypeUtils.getDataTypeParser(ed, DataTypeParsers.PRESENTATION);
Collections.sort(enumValues, (EnumValue arg0, EnumValue arg1) -> {
String arg0String = unparser.unparseEnumValue(ed, arg0);
String arg1String = unparser.unparseEnumValue(ed, arg1);
if (arg0String.length() == 0 || arg1String.length() == 0 || !Character.isLetterOrDigit(arg0String.charAt(0)) || !Character.isLetterOrDigit(arg1String.charAt(0)))
return arg0.compareTo(arg1);
else
return arg0String.compareTo(arg1String);
});
int size = enumValues.size();
IEntity[] values = new IEntity[size];
for (int i = 0; i < size; i++) values[i] = GenericEntityFactory.instance.create(ed, enumValues.get(i));
setResult(values);
break;
case BOOLEAN:
setResult(new IEntity[] { GenericEntityFactory.instance.create(ed, true), GenericEntityFactory.instance.create(ed, false) });
break;
default:
}
}
use of org.whole.lang.model.EnumValue in project whole by wholeplatform.
the class DefaultDataTypePresentationParser method parseEnumValue.
public EnumValue parseEnumValue(EntityDescriptor<?> ed, String value) {
EnumType<?> dataEnumType = ed.getDataEnumType();
if (dataEnumType == null)
throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
EnumValue result = dataEnumType.valueOf(value);
if (result != null)
return result;
for (Iterator<? extends EnumValue> i = dataEnumType.iterator(); i.hasNext(); ) {
EnumValue enumValue = i.next();
if (enumValue.getName().equalsIgnoreCase(value))
return enumValue;
}
throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
}
use of org.whole.lang.model.EnumValue in project whole by wholeplatform.
the class DefaultDataTypePersistenceParser method parseEnumValue.
public EnumValue parseEnumValue(EntityDescriptor<?> ed, String value) {
EnumType<?> dataEnumType = ed.getDataEnumType();
if (dataEnumType == null)
throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
EnumValue result = dataEnumType.valueOf(value);
if (result == null)
throw new WholeIllegalArgumentException(WholeMessages.no_data_type);
return result;
}
Aggregations