Customizing external entity dependencies
The current promotion system's external entities may not expose sufficient attributes to support your promotions. In this case, introduce additional attributes. There are two ways to do this. The first method is very common in other areas of Java development. In the promotions system, external entities are implemented using the following pattern (using order as an example):
To introduce a custom attribute:
- Extend the WCSOrder object so that the new class exposes the new attribute.
- Extend the WCSOrderFactory class so that the new implementation starts to serve up the extended WCSOrder objects
- Implement the custom OrderFactory implementation class.
- Register the custom implementation in the ExternalEntityFactoryRegistry section of the PromotionEngine configuration.
- You must restart WebSphere Commerce before the changes take effect.
The second approach involves using dynamic attributes. A dynamic attribute is a mechanism provided by the PromotionEngine to extend the objects that support DynamicAttribute without modifying the existing implementation of these objects. The following diagram shows the design of the DynamicAttribute feature:
A dynamic attribute is identified by a key. This key has two attributes: a type, and a name. Both attributes are strings. The type attribute is the fully qualified name of the class for which the dynamic attribute is defined. This class must implement the SupportDynamicAttribute tag interface. Currently, all of the external entities implement this interface. The name is the name of the dynamic attribute. Any dynamic attribute must implement the DynamicAttribute interface, which is a subclass of XMLizable. Dynamic attributes are registered and managed using the DynamicAttributePersistenceManager. The registration is done in the
PX_DYNATTR database table.At runtime, the following code fragment can be used to compute the value of a dynamic attribute for an object that supports dynamic attributes. It returns an Object that is the value of the dynamic attribute (as identified by the aKey parameter) for anObj (which implements the SupportDyanmicAttribute interface).
DynamicAttributeManager .getInstance() .getAttribute( DynamicAttributeKey aKey, SupportDynamicAttribute anObj)
If a dynamic attribute is defined for a class C, it applies to all objects O, when Java test "O instance of C" returns true.
Caution: Dynamic attribute support has not undergone vigorous testing. While it is supported, it may generate unexpected results.
Related concepts