Author |
Message
|
Veera B |
Posted: Sun Mar 17, 2013 11:49 pm Post subject: If exists equivalent in Java compute |
|
|
Voyager
Joined: 16 Jan 2013 Posts: 76
|
Hi All,
I need to do a if exists .. then logic in Java compute to find if a purticular tree element is present in environment.
not finding much from infocenter ...
please suggest how to achieve this ? |
|
Back to top |
|
 |
Esa |
Posted: Mon Mar 18, 2013 12:03 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
To find out if an element exists in a message tree you can issue MbElement.getFirstElementByPath(), MbElement..evalueateXPath() or MbMessage.evalueateXPath() and examine the result. |
|
Back to top |
|
 |
Tibor |
Posted: Mon Mar 18, 2013 5:02 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
I've just played with getFirstElementByPath() ten minutes ago and you can get a null pointer as a result, if there is no such an element.
OFF: Hi Esa  |
|
Back to top |
|
 |
nukalas2010 |
Posted: Mon Mar 18, 2013 5:40 am Post subject: |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
Dear Veera,
You can try somethign like this..
Code: |
MbElement oReqRoot = contact admin.getMessage().getRootElement();
MbElement oName = oReqRoot.getFirstElementByPath("/XMLNSC/Request/Name");
String sName = null;
if (oName == null)// if it is null the string has been assigned to
// null
{
sName = null;
} else
sName= oName.getValueAsString(); |
|
|
Back to top |
|
 |
Veera B |
Posted: Mon Mar 18, 2013 6:42 pm Post subject: |
|
|
Voyager
Joined: 16 Jan 2013 Posts: 76
|
nukalas2010 wrote: |
Dear Veera,
You can try somethign like this..
Code: |
MbElement oReqRoot = contact admin.getMessage().getRootElement();
MbElement oName = oReqRoot.getFirstElementByPath("/XMLNSC/Request/Name");
String sName = null;
if (oName == null)// if it is null the string has been assigned to
// null
{
sName = null;
} else
sName= oName.getValueAsString(); |
|
Thank you nukalas2010. your logic worked . I don't know java, which made it a bit complicated, but your explanation was so clear. |
|
Back to top |
|
 |
Esa |
Posted: Tue Mar 19, 2013 12:17 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
nukalas2010 wrote: |
Code: |
MbElement oReqRoot = contact admin.getMessage().getRootElement();
|
|
I wonder if this is going to compile
Do we really need this kind of parental control? |
|
Back to top |
|
 |
Veera B |
Posted: Tue Mar 19, 2013 12:59 am Post subject: |
|
|
Voyager
Joined: 16 Jan 2013 Posts: 76
|
Esa wrote: |
nukalas2010 wrote: |
Code: |
MbElement oReqRoot = contact admin.getMessage().getRootElement();
|
|
I wonder if this is going to compile
Do we really need this kind of parental control? |
Nope it will not compile, but the advantage of using IDE's for developing code, makes it simpler to eliminate such syntax or naive errors ...
I may not know java, but i sure know programming ..
i used nukalas2010's logic to develop below code ..
Code: |
MbElement oReqRoot = oGlobalEnvironment.getRootElement();
MbElement oName = oReqRoot.getFirstElementByPath("/variables/status");
String sName = null;
if (oName == null)// if it is null the string has been assigned to
// null
{
sName = null;
} else
{
sName = getValue(oGlobalEnvironment.getRootElement(), "variables/status").toString();
} |
[/quote] |
|
Back to top |
|
 |
Esa |
Posted: Tue Mar 19, 2013 1:19 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Yes, Veera.
I was just referring to this forum's way to automatically replace any words or acronyms that it thinks may be "bad words" with "contact admin".
But in this case nukalas may actually have written a bad word for us to see. .getMessage() is a method of the class MbMessageAssembly. Maybe he named the instance of it with a shorthand name. Like the first three letters of the word "assembly"...
Which would result to ass. But as you can see, it does not get converted to "contact admin", so it is not a bad word in context of mqseries.net. Neither is it's british version arse.
Maybe he created a New ASsembly and named it using the letters that I have written in upper case: contact admin - yes, that's it!
contact admin! |
|
Back to top |
|
 |
nukalas2010 |
Posted: Tue Mar 19, 2013 3:34 am Post subject: |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
Esa wrote: |
nukalas2010 wrote: |
Code: |
MbElement oReqRoot = contact admin.getMessage().getRootElement();
|
|
I wonder if this is going to compile
Do we really need this kind of parental control? |
lol.. It's pretty wonder. I didn't mentioned any bad words except the word called {inA s s e m b l y} there. Is it really a bad word ???
I just taken this name as below..
Code: |
public void evaluate(MbMessageAssembly inA s s e m b l y) throws MbException { |
Now its time to the list of words which it may think it is a "bad word".. before its going to punch me again...  |
|
Back to top |
|
 |
|