In WebSphere ESB, you can do schema validation of messages by setting the validation checkbox on various mediation primitives. Alternatively, you can use code (perhaps in a custom mediation, for example) similar to the following:
BOInstanceValidator boValidator = (BOInstanceValidator) new ServiceManager().locateService("com/ibm/websphere/bo/BOInstanceValidator");
boolean isItValid = boValidator.validate(myDataObject, anEmptyList);
(both of these methods use the same underlying mechanism).
However, there are some limitations to this approach: for example, pattern restrictions aren’t supported on derived types. In that case, you can always do that part of the validation manually, using code such as the following:
boolean valid = java.util.regex.Pattern.matches(myregexpattern, dataObject.getString("myfield"));
Of course, that does require some knowledge of the structure of the Data Object in question and the patterns that apply to it.
Thanks to Kevin Yang and Chris Markes for help with this tip.