Search in sources :

Example 1 with EnumValue

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"));
}
Also used : EnumValue(org.whole.lang.model.EnumValue) Date(java.util.Date) Test(org.junit.Test)

Example 2 with EnumValue

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) EnumValue(org.whole.lang.model.EnumValue) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) PrimitiveType(org.whole.lang.pojo.model.PrimitiveType) PrimitiveType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType) Type(org.whole.lang.pojo.model.Type) MapType(org.whole.lang.pojo.model.MapType) ArrayType(org.whole.lang.pojo.model.ArrayType) ReferenceType(org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType) CollectionType(org.whole.lang.pojo.model.CollectionType) ReferenceType(org.whole.lang.pojo.model.ReferenceType) ProductDeclaration(org.whole.lang.pojo.model.ProductDeclaration) CollectionType(org.whole.lang.pojo.model.CollectionType) Collection(java.util.Collection) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with EnumValue

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:
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) EnumValue(org.whole.lang.model.EnumValue) ArrayList(java.util.ArrayList) IDataTypeParser(org.whole.lang.parsers.IDataTypeParser) DataKinds(org.whole.lang.reflect.DataKinds)

Example 4 with EnumValue

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

Example 5 with EnumValue

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

Aggregations

EnumValue (org.whole.lang.model.EnumValue)7 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)3 Date (java.util.Date)2 Test (org.junit.Test)2 IEntity (org.whole.lang.model.IEntity)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IDataTypeParser (org.whole.lang.parsers.IDataTypeParser)1 ArrayType (org.whole.lang.pojo.model.ArrayType)1 CollectionType (org.whole.lang.pojo.model.CollectionType)1 MapType (org.whole.lang.pojo.model.MapType)1 PrimitiveType (org.whole.lang.pojo.model.PrimitiveType)1 ProductDeclaration (org.whole.lang.pojo.model.ProductDeclaration)1 ReferenceType (org.whole.lang.pojo.model.ReferenceType)1 Type (org.whole.lang.pojo.model.Type)1 PrimitiveType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.PrimitiveType)1 ReferenceType (org.whole.lang.pojo.reflect.PojoEntityDescriptorEnum.ReferenceType)1 DataKinds (org.whole.lang.reflect.DataKinds)1