You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by Steve Loughran <st...@apache.org> on 2005/11/01 11:33:52 UTC

Re: [Axis2] Qnames

Glen Daniels wrote:
> Steve Loughran wrote:
> 
>>
>> I am looking at how to turn the text contents of a SOAPFaultSubCode 
>> into a QName.
>>
>> 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

1. where to put it
2. what the failure policy should be. Return null vs throw exception?

Re: [Axis2] Qnames

Posted by Steve Loughran <st...@apache.org>.
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

Re: [Axis2] Qnames

Posted by Davanum Srinivas <da...@gmail.com>.
#1: maven jar:install
#2: add a project.properties in root and add one line as follows
optional.includes=
#3: just maven from root should work w/o network connection. "maven
all-tests" needs connection

thanks,
dims

On 11/4/05, Steve Loughran <st...@apache.org> wrote:
> Steve Loughran wrote:
> > Sanjiva Weerawarana wrote:
> >
> >> On Thu, 2005-11-03 at 12:59 +0000, Steve Loughran wrote:
> >>
> >>>> IIRC, there are different interpretations for different usages/specs
> >>>> (XPath, XQuery, Schema, etc.), but it might be that this has been
> >>>> cleaned up by now and is more consistent.  We needed the option for
> >>>> Axis 1.
> >>>>
> >>>> We could certainly do the default-ns version now and add a
> >>>> non-defaulting version later if needed.
> >>>>
> >>>
> >>> Right. I've stuck the code in with both. However, we could pull the
> >>> option to choose your action from the OMElement interface (and test),
> >>> then make the method private so the public operation only gives you
> >>> what we decide is appropriate. If nobody objects, that is what I will
> >>> do.
> >>
> >>
> >>
> >> OK this is fine with me ... to me the rules of XML Schema win over the
> >> others but that's prolly too puritan for the ugly real world.
> >
> >
> > ok, I will try and commit a version that doesnt break SAAJ,
>
> I think I've done this, though SAAJ isnt building for me today anyway,
> for dom3 related problems. I have just made sure that the errors coming
> out from there are not related to the resolveQname() method being absent.
>
> I need to understand maven and the build process here a lot more.
>
> 1. how do I tell maven to install the built artifact into the local
> repository?
>
> 2. how do I say to skip a child module (saaj) when trying to do an
> aggregate?
>
> 3. how do I get tests to run behind a firewall. I do have maven setup
> with proxy support properly.
>


--
Davanum Srinivas : http://wso2.com/blogs/

Re: [Axis2] Qnames

Posted by Steve Loughran <st...@apache.org>.
Steve Loughran wrote:
> Sanjiva Weerawarana wrote:
> 
>> On Thu, 2005-11-03 at 12:59 +0000, Steve Loughran wrote:
>>
>>>> IIRC, there are different interpretations for different usages/specs 
>>>> (XPath, XQuery, Schema, etc.), but it might be that this has been 
>>>> cleaned up by now and is more consistent.  We needed the option for 
>>>> Axis 1.
>>>>
>>>> We could certainly do the default-ns version now and add a 
>>>> non-defaulting version later if needed.
>>>>
>>>
>>> Right. I've stuck the code in with both. However, we could pull the 
>>> option to choose your action from the OMElement interface (and test), 
>>> then make the method private so the public operation only gives you 
>>> what we decide is appropriate. If nobody objects, that is what I will 
>>> do.
>>
>>
>>
>> OK this is fine with me ... to me the rules of XML Schema win over the
>> others but that's prolly too puritan for the ugly real world.
> 
> 
> ok, I will try and commit a version that doesnt break SAAJ,

I think I've done this, though SAAJ isnt building for me today anyway, 
for dom3 related problems. I have just made sure that the errors coming 
out from there are not related to the resolveQname() method being absent.

I need to understand maven and the build process here a lot more.

1. how do I tell maven to install the built artifact into the local 
repository?

2. how do I say to skip a child module (saaj) when trying to do an 
aggregate?

3. how do I get tests to run behind a firewall. I do have maven setup 
with proxy support properly.

Re: [Axis2] Qnames

Posted by Steve Loughran <st...@apache.org>.
Sanjiva Weerawarana wrote:
> On Thu, 2005-11-03 at 12:59 +0000, Steve Loughran wrote:
> 
>>>IIRC, there are different interpretations for different usages/specs 
>>>(XPath, XQuery, Schema, etc.), but it might be that this has been 
>>>cleaned up by now and is more consistent.  We needed the option for Axis 1.
>>>
>>>We could certainly do the default-ns version now and add a 
>>>non-defaulting version later if needed.
>>>
>>
>>Right. I've stuck the code in with both. However, we could pull the 
>>option to choose your action from the OMElement interface (and test), 
>>then make the method private so the public operation only gives you what 
>>we decide is appropriate. If nobody objects, that is what I will do.
> 
> 
> OK this is fine with me ... to me the rules of XML Schema win over the
> others but that's prolly too puritan for the ugly real world.


aah, you should see how Ant abuses XML namespaces


> So, +1 for your proposal.


ok, I will try and commit a version that doesnt break SAAJ,

Re: [Axis2] Qnames

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
On Thu, 2005-11-03 at 12:59 +0000, Steve Loughran wrote:
> > 
> > IIRC, there are different interpretations for different usages/specs 
> > (XPath, XQuery, Schema, etc.), but it might be that this has been 
> > cleaned up by now and is more consistent.  We needed the option for Axis 1.
> > 
> > We could certainly do the default-ns version now and add a 
> > non-defaulting version later if needed.
> > 
> 
> Right. I've stuck the code in with both. However, we could pull the 
> option to choose your action from the OMElement interface (and test), 
> then make the method private so the public operation only gives you what 
> we decide is appropriate. If nobody objects, that is what I will do.

OK this is fine with me ... to me the rules of XML Schema win over the
others but that's prolly too puritan for the ugly real world.

So, +1 for your proposal.

Sanjiva.




Re: [Axis2] Qnames

Posted by Steve Loughran <st...@apache.org>.
Glen Daniels wrote:
> Hi folks:
> 
>>>> The second choice wouldn't be element.getNamespace(), it would be 
>>>> the default namepace.  Both choices are valid depending on context, 
>>>> which is why I believe there was a switch on the Axis1 version of 
>>>> this logic (something like "enableDefaultNS" or something).  
>>>> Recommend a switch, and default to doing default namespace logic.  So:
>>>
>>>
>>> I disagree .. if you resolve a QName in the context of an element and if
>>> the QName has no prefix then it must still be resolved as a qualified
>>> name - thereby inheriting the default NS. That's what a QName of an attr
>>> or an element resolved in the context of an element; so why should
>>> QNames in content (attribute value or text value) be different?
>>>
>>> So I'm -1 for adding two forms of this.
>>>
>>> Sanjiva.
>>
>>
>> What does XSD say in this regard? things like XmlBeans have a qname 
>> type, so they must implement something. I'd hate to do something 
>> inconsistent from everything else.
> 
> 
> IIRC, there are different interpretations for different usages/specs 
> (XPath, XQuery, Schema, etc.), but it might be that this has been 
> cleaned up by now and is more consistent.  We needed the option for Axis 1.
> 
> We could certainly do the default-ns version now and add a 
> non-defaulting version later if needed.
> 

Right. I've stuck the code in with both. However, we could pull the 
option to choose your action from the OMElement interface (and test), 
then make the method private so the public operation only gives you what 
we decide is appropriate. If nobody objects, that is what I will do.

-steve

Re: [Axis2] Qnames

Posted by Glen Daniels <gl...@thoughtcraft.com>.
Hi folks:

>>> The second choice wouldn't be element.getNamespace(), it would be the 
>>> default namepace.  Both choices are valid depending on context, which 
>>> is why I believe there was a switch on the Axis1 version of this 
>>> logic (something like "enableDefaultNS" or something).  Recommend a 
>>> switch, and default to doing default namespace logic.  So:
>>
>> I disagree .. if you resolve a QName in the context of an element and if
>> the QName has no prefix then it must still be resolved as a qualified
>> name - thereby inheriting the default NS. That's what a QName of an attr
>> or an element resolved in the context of an element; so why should
>> QNames in content (attribute value or text value) be different?
>>
>> So I'm -1 for adding two forms of this.
>>
>> Sanjiva.
> 
> What does XSD say in this regard? things like XmlBeans have a qname 
> type, so they must implement something. I'd hate to do something 
> inconsistent from everything else.

IIRC, there are different interpretations for different usages/specs 
(XPath, XQuery, Schema, etc.), but it might be that this has been 
cleaned up by now and is more consistent.  We needed the option for Axis 1.

We could certainly do the default-ns version now and add a 
non-defaulting version later if needed.

--Glen

Re: [Axis2] Qnames

Posted by Steve Loughran <st...@apache.org>.
Sanjiva Weerawarana wrote:
> On Tue, 2005-11-01 at 12:39 -0500, Glen Daniels wrote:
> 
>>The second choice wouldn't be element.getNamespace(), it would be the 
>>default namepace.  Both choices are valid depending on context, which is 
>>why I believe there was a switch on the Axis1 version of this logic 
>>(something like "enableDefaultNS" or something).  Recommend a switch, 
>>and default to doing default namespace logic.  So:
> 
> 
> I disagree .. if you resolve a QName in the context of an element and if
> the QName has no prefix then it must still be resolved as a qualified
> name - thereby inheriting the default NS. That's what a QName of an attr
> or an element resolved in the context of an element; so why should
> QNames in content (attribute value or text value) be different?
> 
> So I'm -1 for adding two forms of this.
> 
> Sanjiva.
> 
> 

What does XSD say in this regard? things like XmlBeans have a qname 
type, so they must implement something. I'd hate to do something 
inconsistent from everything else.

Re: [Axis2] Qnames

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
On Tue, 2005-11-01 at 12:39 -0500, Glen Daniels wrote:
> 
> The second choice wouldn't be element.getNamespace(), it would be the 
> default namepace.  Both choices are valid depending on context, which is 
> why I believe there was a switch on the Axis1 version of this logic 
> (something like "enableDefaultNS" or something).  Recommend a switch, 
> and default to doing default namespace logic.  So:

I disagree .. if you resolve a QName in the context of an element and if
the QName has no prefix then it must still be resolved as a qualified
name - thereby inheriting the default NS. That's what a QName of an attr
or an element resolved in the context of an element; so why should
QNames in content (attribute value or text value) be different?

So I'm -1 for adding two forms of this.

Sanjiva.



Re: [Axis2] Qnames

Posted by Steve Loughran <st...@apache.org>.
Eran Chinthaka wrote:
> Hmm,
> 
> I like to name this method as getTextAsQName().
> 
> Actually I was initialy confused what you need to do, but after the code
> snippet from Steve I understood the real requirement.
> 
> I can't understand why you are passing a String to the resolveQName
> method if this methid is *in* the OMElement. I think the requirement is
> to get the text in an OMElement as a QName. So, IMHO,
> OMElement.getTextAsQName() is much better.
> 

But I also need to: resolve attributes or elements in a list. So 
getTextAsQName() is a helper for the specific need to get the text as a 
qname.

Re: [Axis2] Qnames

Posted by Eran Chinthaka <ch...@opensource.lk>.
Hmm,

I like to name this method as getTextAsQName().

Actually I was initialy confused what you need to do, but after the code
snippet from Steve I understood the real requirement.

I can't understand why you are passing a String to the resolveQName
method if this methid is *in* the OMElement. I think the requirement is
to get the text in an OMElement as a QName. So, IMHO,
OMElement.getTextAsQName() is much better.


Glen Daniels wrote:

>> ":localonly"        //error?
>
>
> Error.
>
>> "prefixonly:"        //error?
>
>
> Error.
>
>> ":"                //should be caught by previous logic
>
>
> +1
>
>> "nocolon"        //assume ns="" or ns=element.getNamespace()
>
>
> The second choice wouldn't be element.getNamespace(), it would be the
> default namepace.  Both choices are valid depending on context, which
> is why I believe there was a switch on the Axis1 version of this logic
> (something like "enableDefaultNS" or something).  Recommend a switch,
> and default to doing default namespace logic.  So:
>
>     public QName resolveQName(String text) {
>         return resolveQName(text, true);
>     }
>
>     public QName resolveQName(String text, boolean useDefaultNS) {
>         int colon = text.indexOf(':');
>         String prefix;
>         if (colon == 0) return null;
>         if (colon < 0) {
>             // No prefix - behave appropriately
>             if (useDefaultNS) {
>                 // Assuming findNamespace(null, "") returns
>                 // the default ns below...
>                 prefix = "";
>             } else {
>                 return new QName(text);
>             }
>         } else {
>             prefix = text.substring(0, colon);
>         }
>         String local = text.substring(colon + 1);
>         //TODO: what if local=="" ?
>
>         OMNamespace namespace = findNamespace(null, prefix);
>         if (namespace == null) {
>             return null;
>         }
>         return new QName(namespace.getName(), local, prefix);
>     }
>
>
> --Glen
>
>


Re: [Axis2] Qnames

Posted by Glen Daniels <gl...@thoughtcraft.com>.
> ":localonly"        //error?

Error.

> "prefixonly:"        //error?

Error.

> ":"                //should be caught by previous logic

+1

> "nocolon"        //assume ns="" or ns=element.getNamespace()

The second choice wouldn't be element.getNamespace(), it would be the 
default namepace.  Both choices are valid depending on context, which is 
why I believe there was a switch on the Axis1 version of this logic 
(something like "enableDefaultNS" or something).  Recommend a switch, 
and default to doing default namespace logic.  So:

     public QName resolveQName(String text) {
         return resolveQName(text, true);
     }

     public QName resolveQName(String text, boolean useDefaultNS) {
         int colon = text.indexOf(':');
         String prefix;
         if (colon == 0) return null;
         if (colon < 0) {
             // No prefix - behave appropriately
             if (useDefaultNS) {
                 // Assuming findNamespace(null, "") returns
                 // the default ns below...
                 prefix = "";
             } else {
                 return new QName(text);
             }
         } else {
             prefix = text.substring(0, colon);
         }
         String local = text.substring(colon + 1);
         //TODO: what if local=="" ?

         OMNamespace namespace = findNamespace(null, prefix);
         if (namespace == null) {
             return null;
         }
         return new QName(namespace.getName(), local, prefix);
     }


--Glen

Re: [Axis2] Qnames

Posted by Steve Loughran <st...@apache.org>.
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.
> 
>>> 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
> }

here you go.

     /**
      * Turn a name:value qname string into a propert QName, evaluating 
it in the OMElement context
      *
      * @param text
      * @return null for no such namespace
      */
     public QName resolveQName(String text) {
         int colon = text.indexOf(':');
         if (colon < 0) {
             //things in the local space are local.
             //TODO: is this right? Should they be in the namespace of 
the current element?
             return new QName(text);
         }
         String prefix = text.substring(0, colon);
         String local = text.substring(colon + 1);
         //TODO: what if local=="" ?

         OMNamespace namespace = findNamespace(null, prefix);
         if (namespace == null) {
             return null;
         }
         return new QName(namespace.getName(), local, prefix);
     }

What we have to do is the policy for the following qnames.

":localonly"		//error?
"prefixonly:"		//error?
":"				//should be caught by previous logic
"nocolon"		//assume ns="" or ns=element.getNamespace()

Someone who understands xmlns needs to tell me thr right answers there

Re: [Axis2] Qnames

Posted by Glen Daniels <gl...@thoughtcraft.com>.
>>>>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.

>>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.

--Glen

Re: [Axis2] Qnames

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
On Tue, 2005-11-01 at 10:33 +0000, Steve Loughran wrote:
> Glen Daniels wrote:
> > Steve Loughran wrote:
> > 
> >>
> >> I am looking at how to turn the text contents of a SOAPFaultSubCode 
> >> into a QName.
> >>
> >> 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
> 
> 1. where to put it

Shouldn't it be OMElement.resolve (String)? Eran?

> 2. what the failure policy should be. Return null vs throw exception?

Exception seems more right to me.

Sanjiva.