Pattern Matching Objects that haven't been accessed

I'm using the XML BOM to execute my rules against, and within a ruleset I'm trying to pattern match on a specific class (i.e. Vehicle) without defining where those vehicles live, so that I can fire my rule for each vehicle in my object model. Unfortunately, it's not finding anything and my suspicion is that because I haven't referenced the vehicles anywhere else, it's just inaccessible and is therefore not matched against. Does this ring a bell for anyone, sounds like it's just something basic I'm missing.

You need to let Blaze know that those objects are located somewhere deep in your XML tree. For example, add a simple function that iterates through the object tree, something like

for each Application in request do {

for each Vehicle in it.vehicles do {}

}

Just to make Blaze aware of those objects. But normally our best practice is to try and declare patterns against a specific collection rather than entire working memory - it works faster and is easier to control and avoid unwanted side effects caused by future changes.

Ok, that was my workaround so I guess it'll turn into my permafix. So basically I need a BOM Walker to get to any class instance I wish to eventually pattern match against. my object model is very object oriented. A vehicles could be under one or many different applications. Was hoping to not have to explicitly say which one I wanted to work with so that it can be a plain "Vehicle Rule". Thanks for your help!

It's done this way for performance reasons (to keep unwanted objects from polluting working memory) and also in some cases there is now way for Blaze to know that your object tree contains some object of a specific type. For example, what if your class had method load(int objectType) that is supposed to load the list of Vehicles from a backend database. This lazy loading pattern is used quite often in Hibernate, for example. An attempt by Blaze to insert objects into working memory would result in their premature loading - not to count the possibility that the result of such method could return a generic collection that you are supposed to typecast into something more concrete accordingly to your application's logic. There is no way for Blaze to know that unless you put an explicit code into it, such as my "for each" example.

Rtaher than walking throughech item in your list you can use the built-in method ensureCollectionIsLoaded. This would be more efficient and definitely less typing.

I suspect that the other approach may be more appropriate in your case if your Vehicles objects are stored in many different places in your object model. You can use Xpath expressions to search for all objects of a given type (you can leverage actually a lot more in XPath to select which actual obejcts you want to retrieve). I used it a lot in insurance applications that used the ACCORD schema and it worked beautifully. It saves you from navigating your object model left and right when objects are all over the place.