public String getFieldNameForItemTypeAndName(Class itemType, String itemFieldName) { ImplicitCollectionMappingImpl unnamed = null; for (Iterator iterator = namedItemTypeToDef.keySet().iterator(); iterator.hasNext(); ) { NamedItemType itemTypeForFieldName = (NamedItemType) iterator.next(); ImplicitCollectionMappingImpl def = (ImplicitCollectionMappingImpl) namedItemTypeToDef.get(itemTypeForFieldName); if (itemType == Mapper.Null.class) { unnamed = def; break; } else if (itemTypeForFieldName.itemType.isAssignableFrom(itemType)) { if (def.getItemFieldName() != null) { if (def.getItemFieldName().equals(itemFieldName)) { return def.getFieldName(); } } else { unnamed = def; if (itemFieldName == null) { break; } } } } if (unnamed != null) { return unnamed.getFieldName(); } else { ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass()); return mapper != null ? mapper.getFieldNameForItemTypeAndName(itemType, itemFieldName) : null; } }
public Class getItemTypeForItemFieldName(Class definedIn, String itemFieldName) { ImplicitCollectionMapperForClass mapper = getMapper(definedIn); if (mapper != null) { return mapper.getItemTypeForItemFieldName(itemFieldName); } else { return null; } }
public ImplicitCollectionMapping getImplicitCollectionDefForFieldName( Class itemType, String fieldName) { ImplicitCollectionMapperForClass mapper = getMapper(itemType); if (mapper != null) { return mapper.getImplicitCollectionDefForFieldName(fieldName); } else { return null; } }
public ImplicitCollectionMapping getImplicitCollectionDefForFieldName(String fieldName) { ImplicitCollectionMapping mapping = (ImplicitCollectionMapping) fieldNameToDef.get(fieldName); if (mapping != null) { return mapping; } else { ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass()); return mapper != null ? mapper.getImplicitCollectionDefForFieldName(fieldName) : null; } }
public Class getItemTypeForItemFieldName(String itemFieldName) { ImplicitCollectionMappingImpl def = getImplicitCollectionDefByItemFieldName(itemFieldName); if (def != null) { return def.getItemType(); } else { ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass()); return mapper != null ? mapper.getItemTypeForItemFieldName(itemFieldName) : null; } }
public void add( Class definedIn, String fieldName, String itemFieldName, Class itemType, String keyFieldName) { Field field = null; Class declaredIn = definedIn; while (declaredIn != Object.class) { try { field = declaredIn.getDeclaredField(fieldName); break; } catch (SecurityException e) { throw new InitializationException("Access denied for field with implicit collection", e); } catch (NoSuchFieldException e) { declaredIn = declaredIn.getSuperclass(); } } if (field == null) { throw new InitializationException("No field \"" + fieldName + "\" for implicit collection"); } else if (Map.class.isAssignableFrom(field.getType())) { if (itemFieldName == null && keyFieldName == null) { itemType = Map.Entry.class; } } else if (!Collection.class.isAssignableFrom(field.getType())) { Class fieldType = field.getType(); if (!fieldType.isArray()) { throw new InitializationException( "Field \"" + fieldName + "\" declares no collection or array"); } else { Class componentType = fieldType.getComponentType(); componentType = componentType.isPrimitive() ? Primitives.box(componentType) : componentType; if (itemType == null) { itemType = componentType; } else { itemType = itemType.isPrimitive() ? Primitives.box(itemType) : itemType; if (!componentType.isAssignableFrom(itemType)) { throw new InitializationException( "Field \"" + fieldName + "\" declares an array, but the array type is not compatible with " + itemType.getName()); } } } } ImplicitCollectionMapperForClass mapper = getOrCreateMapper(definedIn); mapper.add(new ImplicitCollectionMappingImpl(fieldName, itemType, itemFieldName, keyFieldName)); }
private ImplicitCollectionMappingImpl getImplicitCollectionDefByItemFieldName( String itemFieldName) { if (itemFieldName == null) { return null; } else { ImplicitCollectionMappingImpl mapping = (ImplicitCollectionMappingImpl) itemFieldNameToDef.get(itemFieldName); if (mapping != null) { return mapping; } else { ImplicitCollectionMapperForClass mapper = ImplicitCollectionMapper.this.getMapper(definedIn.getSuperclass()); return mapper != null ? mapper.getImplicitCollectionDefByItemFieldName(itemFieldName) : null; } } }