commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Akolkar <>
Subject Re: [SCXML] getting set datats in the datamodel
Date Wed, 15 Apr 2009 18:42:45 GMT
On Wed, Apr 15, 2009 at 12:34 PM, Linda Erlenhov
<> wrote:
> Hello
> So I´m back here again.
> My problem now is that I don´t know how to notify.
> I looked at the solution suggested below since I thought it would be the
> easiest and best looking way to implement this.
> The way my first solution worked was to use Observer and Observable. Since
> Observable is a class I could not extend SimpleContext aswell (since
> multiple inheritance from classes is not ok in java) so i just "copied"
> SimpleContext instead since it only implemented two Interfaces, extended
> Observable and modifyed it according to my liking.

I'd do it the other way, extend the Context implementation and add
observable functionality since I claim the latter is the simpler bit
(lower case o here, not referring to the java.util class -- minimally,
(a) maintain a list of observers as an instance field, (b) have an
adder method that adds observers to the list and (c) have the notify
method in question iterate over the observers to notify them of the
value change).

> The problem then was that
> to user timers (as I was asking about in another thread) and they use JEXL.
> So to make the timers work I have to use an JEXL or JEXL extended class. And
> there goes my Observable.

Timers don't need JEXL, you can continue using whatever EL you were
using (extend the corresponding Context and Evaluator implementations
-- if you were in fact using Commons JEXL, you'd extend JexlContext
and JexlEvaluator and so on).

> I am aware that this might be a java question instead of a SCXML question
> and if so I apologise. Maybe you can see something that I have missed or
> help me with where I should post this question. I´ve stared a bit too long
> at my code by now. Is there another way to do this?

Its a bit more of a Java question than an SCXML question, yes. You
could post to any Java forums / try search engines.


> best regards
> //Linda
>> >>
>> >>  * Use a custom Context implementation - This will allow you to
>> >> intercept data changes, à la pointcut at
>> >> oacs.Context#set(String,Object), and get notifications that way
>> >
>> >
>> > This could possibly be of intrest, but I´m still not 100% sure on how the
>> > context works. Where would these notifications "arrive"
>> >
>> <snip/>
>> This is another approach, some background:
>> I'll sketch an outline here -- say we have MyContext extending
>> SimpleContext where MyContext#set(String,Object) looks like:
>>   public void set(String name, Object value) {
>>      // inherit behavior
>>      super.set(name, value);
>>      // notifications you need
>>      notify(name, value);
>>   }
>> and a MyEvaluator extending the Evaluator you are currently using
>> whose newContext() method does this:
>>   public Context newContext(Context parent) {
>>      return new MyContext(parent);
>>   }
>> then using this evaluator with the SCXMLExecutor instances like so:
>>   SCXMLExecutor exec = new SCXMLExecutor();
>>   ...
>>   exec.setEvaluator(new MyEvaluator());
>> ties in the above "pointcut" behavior causing notifications for any
>> data changes within the state machine. Adjust outline per
>> requirements.
>> -Rahul
>> > best regards
>> > //Linda
>> >

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message