axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Loughran <ste...@apache.org>
Subject Re: [Axis2] Qnames
Date Tue, 01 Nov 2005 13:57:11 GMT
Glen Daniels wrote:
>>>>> Is there a utility function to map string->qname in the context of

>>>>> an Element?
>>>>
>>>>
>>>> If there isn't yet, we should add one (Axis 1's MessageElement has 
>>>> this, and it's generally hugely useful).
>>>
>>>
>>> I've done it, just dont know
> 
> 
> Thanks Steve!
> 
>>> 1. where to put it
>>
>>
>> Shouldn't it be OMElement.resolve (String)? Eran?
> 
> 
> OMElement.getQNameFromString(String) or
> OMElement.resolveQName(String)
> 
> either works for me.

OK. do you want to do the tests then :)

> 
>>> 2. what the failure policy should be. Return null vs throw exception?
>>
>>
>> Exception seems more right to me.
> 
> 
> Really?  I was thinking null would be better to avoid a ton of try/catch 
> blocks.
> 
> QName foo = element.resolveQName("foo:bar");
> if (foo != null) {
>   // do something useful
> }
> 
> vs.
> 
> QName foo = null;
> try {
>   foo = element.resolveQName("foo:bar");
> } catch (NoNamespaceException e) {
>   // fail
> }
> // do something useful
> 
> I just find it easier to write code like the first style, where I can 
> declare and assign the variable in the same place without wrapping 
> *everything* in try/catch.

It really depends what you want to do. Sometimes null is good; sometimes 
exceptions (it would probably be that runtimeexception derivative 
OMParserException) is better.

you could have both:

resolveQName(string s)
resolveQNameExcepting(string s) throws OMParserException

-steve

Mime
View raw message