Author |
Message
|
goffinf |
Posted: Wed Dec 03, 2008 8:51 am Post subject: getGlobalEnvironment |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
Broker version 6.1 / Windows
Is it possible to call getGlobalEnvironment() from the constructor of a custom node ?
I want to add stuff onto the global environment when the node is loaded by the broker rather when the evaluate() method is called.
My node is not an MBInputNode (if that makes a difference).
Obviosuly when evaluate is called an MbMessageAssembly is passed in, and from there it is possible to get to the global environment thus :-
public void evaluate(MbMessageAssembly contact admin) throws MbException {
....
MbMessage inMessage = contact admin.getMessage();
MbMessage outMessage = new MbMessage(inMessage);
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin, outMessage);
MbElement envRoot = outAssembly.getGlobalEnvironment().getRootElement();
...
but I don't have an MbMessageAssembly in the constructor. Is it possible to create one from scratch ??
Thanks
Fraser. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Dec 03, 2008 8:55 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The Global Environment doesn't exist outside the execution of a message flow.
You can create persistent data structures in the constructor and then populate Global Environment from that, but the Environment tree does not exist until you are in the evaluate method or in a run method of an Input plugin node. |
|
Back to top |
|
 |
goffinf |
Posted: Wed Dec 03, 2008 9:27 am Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
mqjeff wrote: |
The Global Environment doesn't exist outside the execution of a message flow.
You can create persistent data structures in the constructor and then populate Global Environment from that, but the Environment tree does not exist until you are in the evaluate method or in a run method of an Input plugin node. |
Yes I see. Thanks.
Slight change of direction then. Actually all I need is an MbElement to hold some XML as a string (i.e. I don't want it to be parsed/escaped). Can I cruft up an MbElement like this ? :-
MbMessage msg = new MbMessage();
MbElement msgRoot = msg.getRootElement();
MbElement msgParser = msgRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
MbElement tempElement = msgParser.createElementAsLastChild(MbElement.TYPE_NAME);
tempElement.setName("myElement");
MbElement finalElement = tempElement.createElementAsLastChild(MbElement.TYPE_VALUE, "myElementname", "<foo/>");
Fraser. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Dec 03, 2008 11:38 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
I assume that your goal is not just to put stuff into the global environment. You want it there in order to do something, What are you really trying to do? |
|
Back to top |
|
 |
goffinf |
Posted: Wed Dec 03, 2008 1:36 pm Post subject: |
|
|
Chevalier
Joined: 05 Nov 2005 Posts: 401
|
kimbert wrote: |
I assume that your goal is not just to put stuff into the global environment. You want it there in order to do something, What are you really trying to do? |
Actually I was using the Environment as a location for data that I was passing to the IA91 CacheNodes putIntoNamedCache method. It expects 2 arguments of type MbElement. This was fine until I realised that I wanted to load data into the cache at the point when one of my custom nodes was loaded by Broker (the cached data is for this nodes use later on when it gets called in a flow), and that I don't have access to the Environment until evaluate is called (as mqjeff said above).
Anyway it looks like I can construct an MbMessage from scratch and from that an MbElement. I've tested it and it seems to work OK.
Thanks for asking
Fraser. |
|
Back to top |
|
 |
|