Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Ce contenu n'est pas disponible dans la langue sélectionnée.
35.3. Widget Vendor Example
35.3.1. Widget Ordering Interface Copier lienLien copié sur presse-papiers!
checkWidgets and placeWidgetOrder. Example 35.12, “Widget Ordering Interface” shows the interface for the ordering service.
Example 35.12. Widget Ordering Interface
Example 35.13. Widget Ordering SEI
35.3.2. The checkWidgets Operation Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
checkWidgets is a simple operation that has a parameter that is the head member of a substitution group. This operation demonstrates how to deal with individual parameters that are members of a substitution group. The consumer must ensure that the parameter is a valid member of the substitution group. The service must properly determine which member of the substitution group was sent in the request.
Consumer implementation Copier lienLien copié sur presse-papiers!
checkWidgets() without using any special code. When developing the logic to invoke checkWidgets() you can pass in an object of one of the classes generated to support the widget substitution group.
checkWidgets()” shows a consumer invoking checkWidgets().
Example 35.14. Consumer Invoking checkWidgets()
Service implementation Copier lienLien copié sur presse-papiers!
checkWidgets() gets a widget description as a WidgetType object, checks the inventory of widgets, and returns the number of widgets in stock. Because all of the classes used to implement the substitution group inherit from the same base class, you can implement checkWidgets() without using any JAXB specific APIs.
widget extend the WidgetType class. Because of this fact, you can use instanceof to determine what type of widget was passed in and simply cast the widgetPart object into the more restrictive type if appropriate. Once you have the proper type of object, you can check the inventory of the right kind of widget.
checkWidgets()” shows a possible implementation.
Example 35.15. Service Implementation of checkWidgets()
35.3.3. The placeWidgetOrder Operation Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
placeWidgetOrder uses two complex types containing the substitution group. This operation demonstrates to use such a structure in a Java implementation. Both the consumer and the service must get and set members of a substitution group.
Consumer implementation Copier lienLien copié sur presse-papiers!
placeWidgetOrder() the consumer must construct a widget order containing one element of the widget substitution group. When adding the widget to the order, the consumer should use the object factory methods generated for each element of the substitution group. This ensures that the runtime and the service can correctly process the order. For example, if an order is being placed for a plastic widget, the ObjectFactory.createPlasticWidget() method is used to create the element before adding it to the order.
WidgetOrderInfo object.
Example 35.16. Setting a Substitution Group Member
Service implementation Copier lienLien copié sur presse-papiers!
placeWidgetOrder() method receives an order in the form of a WidgetOrderInfo object, processes the order, and returns a bill to the consumer in the form of a WidgetOrderBillInfo object. The orders can be for a plain widget, a plastic widget, or a wooden widget. The type of widget ordered is determined by what type of object is stored in widgetOrderForm object’s widget property. The widget property is a substitution group and can contain a widget element, a woodWidget element, or a plasticWidget element.
JAXBElement<? extends T> object's getName() method to determine the element's QName. The QName can then be used to determine which element in the substitution group is in the order. Once the element included in the bill is known, you can extract its value into the proper type of object.
placeWidgetOrder()” shows a possible implementation.
Example 35.17. Implementation of placeWidgetOrder()
placeWidgetOrder()” does the following:
- 1
- Instantiates an object factory to create elements.
- 2
- Instantiates a
WidgetOrderBillInfoobject to hold the bill. - 3
- Gets the number of widgets ordered.
- 4
- Gets the local name of the element stored in the order.
- 5
- Checks to see if the element is a
woodWidgetelement. - 6
- Extracts the value of the element from the order to the proper type of object.
- 7
- Creates a
JAXBElement<T>object placed into the bill. - 8
- Sets the bill object's widget property.
- 9
- Sets the bill object's amountDue property.