From: Matthias B. <inf...@mb...> - 2004-01-31 02:15:44
|
Hi Chad and the others, > Well if we do stick to the validate upon creation of > decorators (which seems the best way to handle it, I'm > not sure how we could validate > the meta model classes at load time). Why don't we > just put a check in, (store the validated elements in > a ThreadLocal variable for instance?) to see if the > element has been validated? That way if that specific > element HAS been validated you just return instead of > validating (therefore breaking out of the possibility > of an infinite loop). good idea. However, I would not use a thread-local variable but the decorator factory itself. An alternative would be the following: Just before we put the reference to the model element into the Velocity context, we call validate(): velocityContext.put("model", df.createDecoratorObject(model)); velocityContext.put("class", df.createDecoratorObject((ModelElement) modelElement)); replaced by: ModelDecorator decoratedModel = df.createDecoratorObject(model); decoratedModel.validate(); velocityContext.put("model", decoratedModel); DecoratorBase decoratedModelElement = df.createDecoratorObject((ModelElement) modelElement); decoratedModelElement.validate(); velocityContext.put("class", decoratedModelElement); And then, each validate() method must also delegate to all dependent decorators. Maybe, this will perform worse because all decorators are always instantiated, regardless of whether they are used or not. A third alternative would be to add a boolean field "validated" to DecoratorBase: void validate() { if (validated) return; // do the validation ... validated = true; } This is the "low tech" alternative - I like that! :-) Cheers... Matthias --- Matthias Bohlen "Consulting that helps project teams to succeed..." http://www.mbohlen.de/ |