use of org.whole.lang.pojo.model.ArrayType in project whole by wholeplatform.
the class PojoUtils method calculateTypeName.
public static String calculateTypeName(Type type) {
String typeName = null;
switch(type.wGetEntityDescriptor().getOrdinal()) {
case PrimitiveType_ord:
typeName = StringUtils.toUpperCap(type.wStringValue()) + "Data";
break;
case ReferenceType_ord:
typeName = StringUtils.toSimpleName(type.wStringValue());
break;
case ArrayType_ord:
ArrayType arrayType = (ArrayType) type;
typeName = calculateTypeName(arrayType.getElementType()) + "Array";
break;
case CollectionType_ord:
CollectionType collectionType = (CollectionType) type;
String interfaceName = collectionType.getCollectionInterface().wEnumValue().toString();
typeName = calculateTypeName(collectionType.getElementType()) + interfaceName;
break;
case MapType_ord:
MapType mapType = (MapType) type;
typeName = calculateTypeName(mapType.getKeyType()) + "To" + calculateTypeName(mapType.getValueType()) + "Map";
break;
}
return typeName;
}
use of org.whole.lang.pojo.model.ArrayType 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.pojo.model.ArrayType in project whole by wholeplatform.
the class PojoUtils method create.
/*
* expects a normalized library
*/
public static Object create(IEntity fromEntity, Library library) {
// find product type
EntityDescriptor<?> ed = fromEntity.wGetEntityDescriptor();
ProductDeclaration productDeclaration = findProductDeclarationByTemplateName(ed, library);
if (productDeclaration == null)
throw new IllegalStateException("Cannot find type mapping for entity: " + fromEntity);
// translate contents as needed
Object toObject = null;
switch(productDeclaration.wGetEntityDescriptor().getOrdinal()) {
case PojoDeclaration_ord:
toObject = createInstance(fromEntity, (PojoDeclaration) productDeclaration, library);
translate(fromEntity, toObject, (PojoDeclaration) productDeclaration, library);
break;
case EnumDeclaration_ord:
String enumValue = DefaultDataTypePersistenceParser.instance.unparseEnumValue(fromEntity.wGetEntityDescriptor(), fromEntity.wEnumValue());
toObject = createEnumValue((EnumDeclaration) productDeclaration, enumValue);
break;
case // TODO
AnnotationDeclaration_ord:
break;
case DataTypeDeclaration_ord:
Type type = ((DataTypeDeclaration) productDeclaration).getName();
switch(type.wGetEntityDescriptor().getOrdinal()) {
case PrimitiveType_ord:
case ReferenceType_ord:
toObject = fromEntity.wGetValue();
break;
case ArrayType_ord:
toObject = Array.newInstance(getClass(((ArrayType) type).getElementType()), fromEntity.wSize());
for (int i = 0; i < fromEntity.wSize(); i++) {
IEntity element = fromEntity.wGet(i);
Array.set(toObject, i, create(element, library));
}
break;
case CollectionType_ord:
Collection<Object> toCollection = ((CollectionType) type).getCollectionInterface().getValue().equals(CollectionInterfaceEnum.Set) ? new HashSet<Object>() : new ArrayList<Object>();
IEntityIterator<IEntity> ci = IteratorFactory.childIterator();
ci.reset(fromEntity);
for (IEntity feature : ci) toCollection.add(create(feature, library));
toObject = toCollection;
break;
case MapType_ord:
Map<Object, Object> toMap = new HashMap<Object, Object>();
for (int i = 0; i < fromEntity.wSize(); i++) {
IEntity key = fromEntity.wGet(i);
IEntity value = fromEntity.wGet(key);
toMap.put(create(key, library), create(value, library));
}
toObject = toMap;
break;
}
break;
}
return toObject;
}
use of org.whole.lang.pojo.model.ArrayType in project whole by wholeplatform.
the class ArrayTypePart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
List<IEntity> list = new ArrayList<IEntity>(1);
ArrayType entity = getModelEntity();
list.add(entity.getElementType());
return list;
}
Aggregations