public Class<?> getTargetType() { Class<?> clazz = getComponentType(); if (clazz == null) { clazz = getType(); } return clazz; }
@SuppressWarnings("unchecked") private Object convertClassReference(NODE value, MappedPath propertyPath, MappedProperty mappedProperty) { if (value instanceof UID) { return convertClassReference((UID) value, mappedProperty.getComponentType()); } else { throw new BindException(propertyPath, "bnode or literal", value); } }
@SuppressWarnings("unchecked") private Object convertArray(MappedPath propertyPath, Collection<? extends NODE> values, UID context) throws InstantiationException, IllegalAccessException { MappedProperty<?> mappedProperty = propertyPath.getMappedProperty(); Class<?> targetType = mappedProperty.getComponentType(); int size = values.size(); if (size == 1) { NODE node = values.iterator().next(); if (node instanceof ID) { if (mappedProperty.isList()) { values = convertList((ID) node, context); } else if (mappedProperty.isContainer()) { values = convertContainer((ID) node, context, mappedProperty.isIndexed()); } } // TODO else log error? } // TODO else log error? Object array = Array.newInstance(targetType, values.size()); int i = 0; for (NODE value : values) { if (value != null) { Array.set(array, i++, convertValue(value, targetType, propertyPath)); } else { Array.set(array, i++, null); } } return array; }
@SuppressWarnings("unchecked") private Object convertCollection(MappedPath propertyPath, Collection<? extends NODE> values, UID context) throws InstantiationException, IllegalAccessException { MappedProperty<?> mappedProperty = propertyPath.getMappedProperty(); Class<?> targetType = mappedProperty.getComponentType(); int size = values.size(); if (size == 1) { NODE node = values.iterator().next(); if (node instanceof ID) { if (mappedProperty.isList()) { values = convertList((ID) node, context); } else if (mappedProperty.isContainer()) { values = convertContainer((ID) node, context, mappedProperty.isIndexed()); } } // TODO else log error? } // TODO else log error? Class collectionType = mappedProperty.getCollectionType(); Collection collection = (Collection) collectionType.newInstance(); for (NODE value : values) { if (value != null) { collection.add(convertValue(value, targetType, propertyPath)); } else { collection.add(null); } } return collection; }
private boolean isPolymorphic(MappedProperty<?> mappedProperty) { if (mappedProperty.isCollection() || mappedProperty.isMap()) { return configuration.isPolymorphic(mappedProperty.getComponentType()); } else { return configuration.isPolymorphic(mappedProperty.getType()); } }
Class<?> type = property.getType(); if (property.isCollection() || property.isMap()) { type = property.getComponentType();
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())); } } }
@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; }
if (property.getRange().isEmpty()) { RDFSClass<?> componentType = processClass(session, mappedProperty.getComponentType(), resources); if (useTypedLists && componentType != null) { property.addRange(new TypedList(cuid.ns(), componentType)); processClass(session, mappedProperty.getComponentType(), resources); if (componentType != null) {
componentType = property.getDynamicCollectionComponentType(); } else { componentType = property.getComponentType();
assertEquals(Parent.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited()); assertEquals(FirstChild.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited()); assertEquals(NestedChild.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited()); assertEquals(SecondChild.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited()); assertEquals(Parent.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited());