Re: java object as pertinent data.

[email protected] Thu, 8 Sep 2005 20:47:12 -0400
Newsgroups gmane.comp.java.enhydra.shark
Message-ID <OF921CA292.15CEAEA5-ON85257076.0083B0AC-85257077.000453A8@intellicare.com>
Hi Vojtech, here's an example of what you can do:

Step 1. Write a trivial class (I called mine 
com.intellicare.asterisk.Agent.java). Make sure it is serializable 
(important!).
Step 2. Open your JaWE editor. Open the xpdl that you want to use.
Step 3. pull down Package -> Type Declarations. Click "New". Enter: 
id:agent, name: agent, Type: External reference, Location: 
com.intellicare.asterisk.Agent. Click OK.
Step 4. pull down menu Package -> workflow relevant data. Click New. 
Enter: id: agentWfdata, name: agentWfdata, isArray: false, Type: declared 
type. The dropdown menu subtype will now appear with your item "agent" in 
it. Pick that.Click Ok.
You are done with your xpdl now.
Now the wf data variable agentWfdata will be available to your Java/Shark 
app as follows:

1. In order to access/initialise it within your Java program, here's what 
you do: Assume you have Shark initialised and your process has started. 
Assume you have objects WfActivity currentActivity and Agent agent. Then 
you can update the wfdata variable with agent as follows:

                Map processContextMap = 
currentActivity.container().process_context();
                processContextMap.put("agentWfdata", agent);
                currentActivity.set_result(processContextMap); 
                currentActivity.complete();

2. Now wf data variable agentWfdata is available to all activities of your 
process. For example you can declare an application in your xpdl this way:
step(i) Open your xpdl in JaWE editor. pull down Package -> Application. 
Enter id:myApp, name:myApp, Then "new" formal parameter with 
id:agentFormalParam, mode:in and out, type:declared type. Again you should 
get the choice of "agent" in your drop down menu for decalred type. Click 
OK. Now suppose one of your activities has "Tools" mapped to this 
application, then the *actual* parameter that you can map to the formal 
parameter "agentFormalParam" is "agentWfData". This is because they both 
are of type decalred type "agent".
step (ii). Now in your Java/Shark program you can write a toolagent which 
can access the wfdata "agentWfdata " as follows:
Assume your toolagent has just that one AppParam, thenwithin the execute 
method:
public static void execute(AppParameter param1) {
        Agent agent = (Agent) param1.the_value; //this is ok since we 
declared this to be *in* and out param
        //now do whatveer you want with agent variable..
 
        Agent agent2 = new Agent(..blah..);
        param1.value = agent2; //this is ok since we declared this is to 
be in and *out* param
        //etc..
}

I have tested all the above in my own web app and it all works. However it 
is all buried within a Shale/JSF/Tiles/asterisk web application so i don't 
think it would be easy to follow if I posted the code.  If the above 
outline is not easy to follow, please let me know and I will try and write 
an easy Java program over the weekend and post that. If, however, this is 
easy enough to follow, let me know that too..:)

One last thing: the JaWE editor is quite nice, but one thing that i didn't 
realise when I first started working with Shark was that when they were 
dropdown lists in a menu, a lot of times, you only saw a blank item, but 
below it, there were more items which in fact were what you wanted to see 
and choose! So lots of times I tried to eneter stuff in the blank item, 
which actually was wrong and I got errors in my xpdl and I couldn't figure 
out what was wrong... (tell me if this is not clear - this was a big 
hurdle for me to cross and it may be what's holding you up..)

Hope this helps - let me know how you make out. this is not really 
difficult, so i think with maybe a bit of help you will get it soon 
enough....:)
Geeta


Vojtech Huser <[email protected]> wrote on 09/08/2005 04:51:50 PM:

> Geeta,
> 
> I have the same problem as Elsa.
> I have read you reply and tried to use it but I get a lot of errors 
> when I try to finish the code. (which you sugested)
> 
> e.g.
> creating correctly the currentActivity object (as WfActivity  object) in 
my 
> TestUsingJavaClassAsParam01.java.
> 
> 
> Is there any complete examle where such  UsingJavaClassAsParam.java 
> would be in full.
> 
> also the code for "metier.class" and the corresponding .xpdl file...
> where it is defined as a type....
> 
> ...rewriting all my objects into string variables and passing those 
> is very tedious. (which is what I have to use since there are some 
> examples for using those...)
> 
> Vojtech
>
message-footer.txt (text/plain, 271 B)
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws