You can extend an existing client library to add more data
to the current service request, handle new data in a service response,
or add new behavior by building an entirely new service request.
Procedure
- Start
WebSphere Commerce Developer.
- Identify the client library to extend (for example, CommonOrderFacadeClient).
- Identify the behavior in the client library that you intend
to add or change (for example, adding additional data to the UserData
element of the Order noun).
- If the extension includes adding more data, identify
the appropriate build ObjectName() method to override to add
more data. Extend the class and override this method. For example,
if you are adding engraving data to a set of order items, you would
add the following code to the
buildOrderItem()
method:
protected OrderItemType[] buildOrderItem(Map parameters, String
actionName) throws OrderException
{
//Snippet below
for (int i=0; i<orderItems.length; i++) //for all of the order
items
{
OrderItemType orderItem = orderItems[i]; //get a particular
order item
//prepare the userData section
UserDataType userData = orderItem.getUserData();
if (userData == null)
{
userData =
CommerceFoundationFactory.eINSTANCE.createUserDataType();
}
orderItem.setUserData(userData);
Map userDataFields = userData.getUserDataField();
//iterate through all the engraving parameters
Set keys = parameters.keySet();
Iterator it = keys.iterator();
while (it.hasNext())
{
String keyName = (String)it.next();
if (keyName.startsWith(ENGRAVINGKEYNAME))//if it is
an engraving attribute
{
String[] values =
(String[])parameters.get(keyName);
//create a new name, value pair type
userDataFields.put(keyName,values[i]);
}
}
}
}
- If the extension includes adding new behavior, extend
the client library and add a method to build a new Service Data Object
request that represents the new behavior.
- Configure the presentation framework to register your extended
client library, to allow the presentation layer to use your extended
library instead of the default.