@SuppressWarnings("unchecked") private Object convertMap(MappedPath propertyPath, Set<? extends NODE> values) { MappedProperty<?> propertyDefinition = propertyPath.getMappedProperty(); Object convertedValue; Class<?> componentType = propertyDefinition.getComponentType(); Class<?> keyType = propertyDefinition.getKeyType(); Map map = new HashMap(); for (NODE value : values) { // Map key Object key = convertValue( getFunctionalValue((ID) value, propertyDefinition.getKeyPredicate(), false, null), keyType, propertyPath); // Map Value Object mapValue; UID valuePredicate = propertyDefinition.getValuePredicate(); if (valuePredicate != null) { mapValue = convertValue(getFunctionalValue((ID) value, valuePredicate, false, null), componentType, propertyPath); } else { mapValue = convertValue(value, componentType, propertyPath); } map.put(key, mapValue); } convertedValue = map; return convertedValue; }
private void collectTypes() { for (MappedClass mappedClass : configuration.getMappedClasses()) { if (mappedClass.isEnum()) { // skip enum types continue; } EntityType entityType = (EntityType) createType(mappedClass.getJavaClass()); for (MappedPath mappedPath : mappedClass.getProperties()) { MappedProperty<?> mappedProperty = mappedPath.getMappedProperty(); Class<?> type = mappedPath.getMappedProperty().getType(); Type propertyType = null; if (type.equals(Map.class)) { propertyType = new SimpleType(Types.MAP, createType(mappedProperty.getKeyType()), createType(mappedProperty.getComponentType())); } else if (type.equals(List.class)) { propertyType = new SimpleType(Types.LIST, createType(mappedProperty.getComponentType())); } else if (type.equals(Set.class)) { propertyType = new SimpleType(Types.SET, createType(mappedProperty.getComponentType())); } else if (type.equals(Collection.class)) { propertyType = new SimpleType(Types.COLLECTION, createType(mappedProperty.getComponentType())); } else { propertyType = createType(type); } entityType.addProperty(createProperty(entityType, mappedPath.getName(), propertyType, mappedProperty.getAnnotations())); } } }
@Test public void MappedClass() throws SecurityException, NoSuchFieldException { Field field = Project.class.getDeclaredField("infos"); assertNotNull(field); MappedClass mappedClass = configuration.getMappedClass(Project.class); boolean containsInfos = false; for (MappedProperty<?> property : mappedClass.getDynamicProperties()) { if (property.isDynamic() && property.getName().equals("infos")) { containsInfos = true; assertEquals(UID.class, property.getKeyType()); assertTrue(Set.class.isAssignableFrom(property.getDynamicCollectionType())); assertEquals(String.class, property.getDynamicCollectionComponentType()); } } assertTrue("Could not find property 'infos'", containsInfos); }