Domain Value Maps in Oracle Service Bus
By Chris Tomkins on Feb 05, 2010
Imagine you are performing a mapping in Oracle Service Bus where a field in your source message may contain one of a number of different values which gets mapped to one of a number of different values in the target message, e.g. you might need to map airport names to airport codes:
|Airport Name||Airport Code|
This sort of mapping is typically called a domain value map as you are mapping from values in one domain to another.
Oracle Service Bus does not yet have built-in support for domain value maps - this is being integrated from the mediator component in SOA Suite and should be available in the 11gR2 release - so how do you handle this type of mapping in the meantime? Well, there are a number of options:
a) Add this information into your XQuery/XSLT transformation in the form of if/then logic
- Not very elegant
- Only really manageable for a small number of entities
b) Use the fn-bea:execute-sql() function to lookup these values from a database
- Good solution when there are lots of entities and their values change regularly
- However, likely to be more expensive in terms of performance and more complex - data source configuration, database setup/maintenance etc.
c) Use a domain value map in Oracle Service Bus
Hey? I thought you said Oracle Service Bus didn’t have domain value map support yet? Not quite, I said it doesn’t have built-in support for domain value maps, but that doesn’t mean we can’t make domain value maps work in the meantime.
The way to do this is the following:
Create a domain value map in JDeveloper
- Create a new SOA application
- Right click on the newly created project within this application and select New
- From the SOA Tier category, select Transformation and in the Items list select Domain Value Map
- Click OK and then give your domain value map a name, description and enter the first couple of values
- Click OK again, and then add some more domain values to your domain value map using the green plus sign until it looks something like this:
- Save your work.
Import the domain value map into Oracle Service Bus
- Create an XQuery transformation file called AirportNamesToAirportCodesDVM using the contents of the domain value map you created by switching to the Source tab in JDeveloper and copying and pasting the whole dvm tag which includes all the data (you don’t need the XML declaration and generated comment above this) into the contents of the XQuery file in Oracle Service Bus
Import the domain value map schema into Oracle Service Bus
- Create an XML schema file for the domain value map using the domain value map schema which can be found here.
Define your XQuery mapping in Oracle Service Bus
- In Oracle Service Bus create a new XQuery transformation and include both the domain value map and your source message (containing the airport name) as source types:
- Set the target type of the transform to be your output message type
- Then in the XQuery mapper drag and drop a wire from the airport name field in the source messages to the airport code airport code field in the target message
- In the Target Expression tab replace $airportName with
and click Apply. This XPath expression basically says: “take the contents of the second column of the row in the domain value map where the first column’s contents equals the name of the airport in my source message”
Your mapping should now look like this:
Test your transform
- Switch to the test tab
- Populate your domain value map with some values (this will be the dvm source variable)
- Switch to the input message source variable and enter the name of the airport (or your full source message if you have done something more complex than this example) and click the green arrow to test your XQuery:
Using the transform in a proxy service message flow
To use the transform in a proxy service message flow (i.e. within an action such as a Replace) you will need to create the dvm variable by adding an Assign action before the action in which you plan to do the transform.
You will then need to use this variable and the source message as inputs to the transformation in your Replace action.
Why use this approach?
- Domain value maps can be used in multiple transformations
- Domain value maps are one of the most efficient way of mapping relatively small, fairly static sets of data (Note: the first invocation of a transformation including a domain value map will take longer as it has to load the domain value map and cache it – subsequent invocations will be faster).
- Having these mapping defined in one places makes it easy for them to be modified if required
- Using JDeveloper to define your domain value map makes it easier to maintain, and means you can use the same domain value map with other SOA Suite components and future proofs it for when domain value maps are fully supported in Oracle Service Bus