{
QName qname = getSchemaType();
final String className = ( qname.getNamespaceURI() + "." + qname.getLocalPart() ).substring( 20 );
// Read attributes
ValueDescriptor descriptor = module.valueDescriptor( className );
StateDescriptor stateDescriptor = descriptor.state();
final Map<QualifiedName, Object> values = new HashMap<>();
while( reader.hasMoreElementReaders() )
{
MessageReader childReader = reader.getNextElementReader();
QName childName = childReader.getName();
QualifiedName childQualifiedName = QualifiedName.fromClass( (Class) typeClass,
childName.getLocalPart() );
PropertyDescriptor propertyDescriptor = stateDescriptor.findPropertyModelByQualifiedName(
childQualifiedName );
Type propertyType = propertyDescriptor.type();
AegisType type = getTypeMapping().getType( propertyType );
Object value = type.readObject( childReader, context );
values.put( childQualifiedName, value );
}
ValueBuilder<?> builder = module.newValueBuilderWithState(
(Class<?>) typeClass,
new Function<PropertyDescriptor, Object>()
{
@Override
public Object map( PropertyDescriptor descriptor1 )
{
return values.get( descriptor1.qualifiedName() );
}
},
new Function<AssociationDescriptor, EntityReference>()
{
@Override
public EntityReference map( AssociationDescriptor descriptor )
{
Object value = values.get( descriptor.qualifiedName() );
if( value == null )
{
return null;
}
return EntityReference.parseEntityReference( value.toString() );
}
},
new Function<AssociationDescriptor, Iterable<EntityReference>>()
{
@Override
public Iterable<EntityReference> map( AssociationDescriptor descriptor )
{
Object value = values.get( descriptor.qualifiedName() );
if( value == null )
{
return Iterables.empty();
}
String[] ids = value.toString().split( "," );
List<EntityReference> references = new ArrayList<>( ids.length );
for( String id : ids )
{
references.add( EntityReference.parseEntityReference( id ) );
}
return references;
}
},
new Function<AssociationDescriptor, Map<String, EntityReference>>()
{
@Override
public Map<String, EntityReference> map( AssociationDescriptor descriptor )
{
Object value = values.get( descriptor.qualifiedName() );
if( value == null )
{
return Collections.emptyMap();
}
String[] namedRefs = value.toString().split( "," );