Skip to content

Object Mapper: XML Parsing

30 December 2009

Recently, I’ve described the object mapper’s domain model and illustrated that it’s still evolving by discussing the “generation gap“. In this post, I talk about the components of the object mapper.

There are two main components to the object mapper. Since the mapper is configured via XML, clearly I need something to read in the XML and initialize the domain model. Because I’m constrained to C# 2.0, I used an XmlReader. To handle malformed mapping XML documents, I wrote an XSD schema and validate incoming XML before parsing.

Each node triggers the creation of a domain object. Each Source and Target is implemented with the Composite pattern as an Element. Sources are comprised of Targets, and Targets are comprised of leaf elements like property mappings.

Each component of the Element Composite exposes an Execute method that calls a Command. There are two sets of commands: one working on objects, the other on elements (properties or fields). For example, there is an ObjectSetter, that simply sets the target to the source. Correspondingly, an ElementSetter sets the target property value to the source property’s value.

Other types of Commands include an ObjectConverter, which invokes the conversion Function on the source and sets the target object equal to the result, and an ElementInjector, which sets a target element equal to a value specified in the mapping XML.

Array transformations are handled by way of a Decorator, which handles the invokation of the decorated Command on each element in the array.

Next post, I’ll talk about how I made some progress on bridging that generation gap.

3 Comments leave one →
  1. neontapir permalink
    15 March 2012 11:59 pm

    I notice this post is poorly rated. What content were you hoping to find?


  1. Object Mapper: Challenges of inferring type information - Neon Tapir
  2. Object Mapper: Conversion Engine and Conditional Commands - Neon Tapir

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: