RE: Event Flow?
Kirk Daries <[email protected]>
| Newsgroups | gmane.comp.java.enhydra.barracuda.general |
|---|---|
| Message-ID | <D09B591872D1D611AF2B0010B5A1AAD0527F3B@WCSMAIL> |
Hi Diez,
I tried point 1.
I changed it to the following code.
Actually snippet here...
if ((moduleId == null) && (browseId == null)) {
ValidateApplication_Listener validateApplication_Listener = new
ValidateApplication_Listener();
listener = validateApplication_Listener.getInstance();
listener.handleEvent(context);
} else if ((moduleId != null) && (browseId == null)) {
ValidateModule_Listener validateModule_Listener = new
ValidateModule_Listener();
listener = validateModule_Listener.getInstance();
listener.handleEvent(context);
} else if ((moduleId != null) && (browseId != null)) {
ValidateBrowseListing_Listener validateBrowseListing_Listener = new
ValidateBrowseListing_Listener();
listener = validateBrowseListing_Listener.getInstance();
listener.handleEvent(context);
}
Unfortunately... this won't work...
E.g.
Calling ValidateBrowseListing_Listener() won't work.. because it relies on
the fact that
the parent listener..ValidateModule_Listener is already called.
Here's my actual event hierachy...
->privateEvent
-->ValidateApplication
---->ValidateUser
------>ValidateModule
--------> ValidateBrowseListing.
Here's the crux of the matter.
I can dynamically... add Template Models to a page based on some config
information.
So eg. MyPageHTML.class can be associated with MyCarModel or MyHouseModel.
My models use the information populated in the event validators.
Which application to get information from, etc, etc.
However... since I can reuse a page with a different model...
I sometimes pass more params to MyPageHTML under certain conditions.
The idea was to automatically validate and populate the structure if the
param exists in
the url.
I suppose I could manually call each eventListener in the correct sequence.
E.g.
ValidateApplication_Listener validateApplication_Listener = new
ValidateApplication_Listener();
ValidateModule_Listener validateModule_Listener = new
ValidateModule_Listener();
ValidateBrowseListing_Listener validateBrowseListing_Listener = new
ValidateBrowseListing_Listener();
ValidateUser_Listener validateUser_Listener = new ValidateUser_Listener();
if ((moduleId == null) && (browseId == null)) {
listener = validateApplication_Listener.getInstance();
listener.handleEvent(context);
} else if ((moduleId != null) && (browseId == null)) {
listener = validateApplication_Listener.getInstance();
listener.handleEvent(context);
listener = validateUser_Listener.getInstance();
listener.handleEvent(context);
listener = validateModule_Listener.getInstance();
listener.handleEvent(context);
} else if ((moduleId != null) && (browseId != null)) {
listener = validateApplication_Listener.getInstance();
listener.handleEvent(context);
listener = validateUser_Listener.getInstance();
listener.handleEvent(context);
listener = validateModule_Listener.getInstance();
listener.handleEvent(context);
listener = validateBrowseListing_Listener.getInstance();
listener.handleEvent(context);
}
But if the hierarchy ever changed.. I'd need to change the validateParams
listener.. :(
Ideally.. I'd like to see a 'addEventForImmediateExecution' method added to
the dispatch queue.
Ok... it's a terrible name.... but you get the gist.
This would solve the above problem. ;)
Regards
KD
-----Original Message-----
From: Diez B. Roggisch [mailto:[email protected]]
Sent: 15 April 2003 01:28
To: [email protected]
Subject: Re: [Barracuda] Event Flow?
Hi Kirk,
> //Read parms fromt request..
> ....bla code here
>
> if ((param1 == null) && (param2 == null)) {
> newEvent = new DefaultValidationEvent();
>
> } else if ((param1 != null) && (param2 == null)) {
> newEvent = new ValidateAndPopulateXYZ();
>
> } else if ((param1 != null) && (param2 != null)) {
> newEvent = new ValidateAndPopulateBlaBla();
> }
>
> if (newEvent != null) {
> newEvent.setSource(event);
> DispatchQueue queue = context.getQueue();
> queue.addEvent(newEvent);
> }
Hmm. two thoughts:
1) Why don't you just call the code instead of loose-coupling it? It
might be less beautiful. But "perverting" the event system isn't
beautiful either. The ideas you had would complicate things a great
deal, I believe.
2) What about splitting your functionality - SomeEvent, and
SomeEventWorker. So SomeEvent-handler simply adds SomeEventWorker to the
queue. By the time that has been done, the ValidationAndPopulateEvent is
already in the queue and will be processed first.
Diez
_______________________________________________
Barracuda mailing list
[email protected]
http://barracudamvc.org/lists/listinfo/barracuda