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 Ajith Ranabahu <aj...@gmail.com> on 2004/12/15 14:41:31 UTC

[Axis2] Namespace serialization problem

Hi all,
When I was writing the serializers I came across the following
problems (they are not actually problems but kind of confusing areas
!) I am talking about serializing OM to TEXT!
Anyway here is the problem.
When you create the OMnodes in a jdom like manner (where there is no
restriction to construction, you can just say new Node()) the
namespace declarations get into a mess! Have a look at the following
piece of code.(BTW this is an actual piece of code from a test class)

  OMNamespace omNs = fac.createOMNamespace("http://localhost/my","my");
  OMElement method =  fac.createOMElement("echoOMElement",omNs) ;
  OMElement value =  fac.createOMElement("myValue",omNs) ;
  value.setValue("Isaac Assimov, the foundation Sega");
  method.addChild(value);

in this case where should the namespace be declared? is it right to
have it in the top most element ?
And what should happen if I am to serialize only the value element ?
Since this is quite messy I did not deal with it at creation but had a
solution for it at the serialization. (this is the approach Srinath
refers to as "mess first and sweep later" :)).
I keep a list of prefixes that has already being written and writes
out the elements own namespace as well as the declared ones if they
are already not written.

Here are some sample outputs
---------------------------------------------------------------------------------------------------------------------
Full Soap output of a sample SOAP document made to an OM.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
   <soapenv:Header>
       <wsa:MessageID
soapenv:mustUnderstand="0">uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>
       <wsa:To soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</wsa:To>
       <wsa:From soapenv:mustUnderstand="0">
           <wsa:Address
xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing"
xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
       </wsa:From>
   </soapenv:Header>
   <soapenv:Body>
       <axis2:echoVoid
xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
   </soapenv:Body>
</soapenv:Envelope>
------------------------------------------------------------------------------------------------------------------------
here is the body element(only) serialised
------------------------------------------------------------------------------------------------------------------------
<soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <axis2:echoVoid
xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
   </soapenv:Body>
----------------------------------------------------------------------------------------------------------------------

So as you can see it provides the desired output eventhough the
representation may be messy underneath (and probably not the most
efficient)!

Any thoughts in improving this?

-- 
Ajith Ranabahu

Re: [Axis2] Namespace serialization problem

Posted by Ajith Ranabahu <aj...@gmail.com>.
On Wed, 15 Dec 2004 13:58:15 -0500, Aleksander Slominski
<as...@cs.indiana.edu> wrote:
> it seems value and method elements are disconnected? should not value be
> child of method?

Well, yeah, I agree. The code should actually create a text node and
add that as a child I guess. Otherwise setValue will be slightly
confusing.

> >  value.setValue("Isaac Assimov, the foundation Sega");
> >  method.addChild(value);
> >
> >in this case where should the namespace be declared? is it right to
> >have it in the top most element ?
> >

Well What I meant here is that in the text form whether the namespace
declaration is supposed to appear in the top most element.

> i like to declare namespace as constant then reuse it and i like to
> build elements directly
> 
> final static O,Namespace NS = fac.createOMNamespace("http://localhost/my","my");
> 
>  // ...
> 
>  OmElement method =  builder.createOMElement(NS, "echoOMElement",) ;
>  OMElement value =  method.addElement(NS, "myValue") ;
>  value.replaceChildrenWithText("Isaac Assimov, the foundation Sega");
> 

Ok, this is fine. But we can do the same (even if we dont make the
variables static) by configuring the builder so that when you say
createNamespace then it returns the correct instance of the namespace
(if created then the created instance)
 
> >And what should happen if I am to serialize only the value element ?
> >Since this is quite messy I did not deal with it at creation but had a
> >solution for it at the serialization.
> >
> serializer will either declare namespace prefixes automatically or fail
> depending how it is set up - i see no problem here.

Yeah but we have to stick to a policy. I mean we can have a default
namespace declaration in each element (ugly method) or introduce our
own namespace prefix and have it declared once.

> 
> >(this is the approach Srinath
> >refers to as "mess first and sweep later" :)).
> >
> >
> hmm: i prefer to call it creative disorder: one needs  chaos to create
> order out of it :)
> 
> >I keep a list of prefixes that has already being written and writes
> >out the elements own namespace as well as the declared ones if they
> >are already not written.
> >
> >
> StAX and XmlPull serializers can do it automatically no need for OM to
> do it ...

Hmmm.. I have to look into this then! 

> alek
> 

-- 
Ajith Ranabahu

Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Ajith Ranabahu wrote:

>On Fri, 17 Dec 2004 09:39:45 +0600, Sanjiva Weerawarana
><sa...@opensource.lk> wrote:
>  
>
>>Wait I'm confused. If you say builder.newElement (NS, localName)
>>then the new element *better* have the namespace declared or
>>its wrong XML+Namespaces.
>>
>>Right??
>>    
>>
>
>Well, Not always but it has its advantages. imagine that you want to
>serialize (into Text) only a part of the Object model (say one single
>element). Then that piece of XML should have the correct namespaces
>declared. However when the whole object model is converted into text,
>the namespaces appear in different places but correctly formatted.
>Have a look at my previos mails for a code sample :)
> 
>  
>
>>So the element node has to include this NS declaration, unless the same
>>NS node exists "up the tree." Since the node isn't parented yet you
>>can't go searning up the tree yet .. so are you suggesting that that
>>search occur at the point of being added as a child of another element?
>>
>>    
>>
>I thought of this. But it seems to be a messy thing. Check the
>namespaces in every addChild operation?
>  
>
>>Even if its declared on the parent the user may have re-declared it.
>>Do we want to "clean up" the XML in that case and remove redundant
>>NS declarations?? Round-tripping would suffer, of course.
>>
>>Sanjiva.
>>    
>>
>
>what I have already done to prevent this and still make it right, I
>deal with it in the serializer. Let the namespace (may be immutable or
>may be not) be bound to elements but the serializer deals with it
>correctly at the time of writing the XML out.
>
>  
>
exactly and serialzier will get right prefixes written which is crucial 
for correct c14n.

alek

-- 
The best way to predict the future is to invent it - Alan Kay


Re: [Axis2] Namespace serialization problem

Posted by Ajith Ranabahu <aj...@gmail.com>.
On Fri, 17 Dec 2004 09:39:45 +0600, Sanjiva Weerawarana
<sa...@opensource.lk> wrote:
> 
> Wait I'm confused. If you say builder.newElement (NS, localName)
> then the new element *better* have the namespace declared or
> its wrong XML+Namespaces.
> 
> Right??

Well, Not always but it has its advantages. imagine that you want to
serialize (into Text) only a part of the Object model (say one single
element). Then that piece of XML should have the correct namespaces
declared. However when the whole object model is converted into text,
the namespaces appear in different places but correctly formatted.
Have a look at my previos mails for a code sample :)
 
> So the element node has to include this NS declaration, unless the same
> NS node exists "up the tree." Since the node isn't parented yet you
> can't go searning up the tree yet .. so are you suggesting that that
> search occur at the point of being added as a child of another element?
> 
I thought of this. But it seems to be a messy thing. Check the
namespaces in every addChild operation?
> 
> Even if its declared on the parent the user may have re-declared it.
> Do we want to "clean up" the XML in that case and remove redundant
> NS declarations?? Round-tripping would suffer, of course.
> 
> Sanjiva.

what I have already done to prevent this and still make it right, I
deal with it in the serializer. Let the namespace (may be immutable or
may be not) be bound to elements but the serializer deals with it
correctly at the time of writing the XML out.

-- 
Ajith Ranabahu

Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Ajith Ranabahu wrote:

>Hi,
>Well, there is! here is the slightly modified code 
>
>       OMFactory factory = OMFactory.newInstance();
>
>       OMNamespace ns1 = factory.createOMNamespace("bar","x");
>       OMElement root = factory.createOMElement("root",ns1);
>
>       OMNamespace ns2 = root.declareNamespace("bar","y");
>
>       OMElement elt1 = factory.createOMElement("foo",ns1);
>       OMElement elt2 = factory.createOMElement("yuck",ns2);
>
>
>       OMText txt1 = factory.createText(elt2,"blah");
>
>       elt2.addChild(txt1);
>       elt1.addChild(elt2);
>       root.addChild(elt1);
>
>       SimpleOMSerializer serializer = new SimpleOMSerializer();
>       serializer.serialize(root, writer);
>
>And the resulting output
>
><x:root xmlns:x="bar" xmlns:y="bar">
> <x:foo>
>     <y:yuck>blah</y:yuck>
>  </x:foo>
></x:root>
>
>I guess this is better than the earlier one but note that you have to
>EXPLICITLY declare the namespace!. What I meant to show you guys is
>that even when you don't declare the namespaces this way, it is better
>if we can have the same serialization. Otherwise if we have more
>elements we will probably see XML's like the following (if the
>declarenamespace method is NOT used).
>
><x:root xmlns:x="bar">
><x:foo2>
> <y:yuck xmlns:y="bar"></y:yuck>
></x:foo2>
><x:foo1>
> <y:yuck xmlns:y="bar"></y:yuck>
></x:foo1>
></x:root>
>
>Of course this is perfectly valid but if we can push the 'y' namespace
>declaration up the tree it will be better. Currently the serializer
>does not try to optimize the namespace declarations.
>
>thoughts ?
>  
>
simple serializer should not try to optimize for it.

if user wants to have namespace declarations on top level element then 
user has to actually declare them otherwise you get into "mind reading" 
APIs ;-)

alek

-- 
The best way to predict the future is to invent it - Alan Kay


RE: [Axis2] Namespace serialization problem

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

Oops, something must have gone wrong somewhere.

I think I removed the method, factory.createNamespace(string,string). (If
not, I will do it :( )

So we have only the declareNamespace(uri, prefix) in the OMElement. My
argument for this approach was that, there can't be a namespace, without an
element being attached to it. That means, every namespace MUST be declared
within an OMElement. So we just need declareNamespace(uri,prefix).

But Alek, was suggesting factory.createNamespace(uri,prefix) so that we have
a global table for urls, so that this has some good effect on memory foot
print.
I think that has to be handled in the implementation level, not exposed to
the user. 

So if that's the case, I think there won't be any serilialization problems,
as Ajith suggested. 

Thankx and regards

-- Eran Chinthaka


>>
>>Hi,
>>Well, there is! here is the slightly modified code
>>
>>       OMFactory factory = OMFactory.newInstance();
>>
>>       OMNamespace ns1 = factory.createOMNamespace("bar","x");
>>       OMElement root = factory.createOMElement("root",ns1);
>>
>>       OMNamespace ns2 = root.declareNamespace("bar","y");
>>
>>       OMElement elt1 = factory.createOMElement("foo",ns1);
>>       OMElement elt2 = factory.createOMElement("yuck",ns2);
>>
>>
>>       OMText txt1 = factory.createText(elt2,"blah");
>>
>>       elt2.addChild(txt1);
>>       elt1.addChild(elt2);
>>       root.addChild(elt1);
>>
>>       SimpleOMSerializer serializer = new SimpleOMSerializer();
>>       serializer.serialize(root, writer);
>>
>>And the resulting output
>>
>><x:root xmlns:x="bar" xmlns:y="bar">
>> <x:foo>
>>     <y:yuck>blah</y:yuck>
>>  </x:foo>
>></x:root>
>>
>>I guess this is better than the earlier one but note that you have to
>>EXPLICITLY declare the namespace!. What I meant to show you guys is
>>that even when you don't declare the namespaces this way, it is better
>>if we can have the same serialization. Otherwise if we have more
>>elements we will probably see XML's like the following (if the
>>declarenamespace method is NOT used).
>>
>><x:root xmlns:x="bar">
>><x:foo2>
>> <y:yuck xmlns:y="bar"></y:yuck>
>></x:foo2>
>><x:foo1>
>> <y:yuck xmlns:y="bar"></y:yuck>
>></x:foo1>
>></x:root>
>>
>>Of course this is perfectly valid but if we can push the 'y' namespace
>>declaration up the tree it will be better. Currently the serializer
>>does not try to optimize the namespace declarations.
>>
>>thoughts ?
>>
>>--
>>Ajith Ranabahu




Re: [Axis2] Namespace serialization problem

Posted by Ajith Ranabahu <aj...@gmail.com>.
Hi,
Well, there is! here is the slightly modified code 

       OMFactory factory = OMFactory.newInstance();

       OMNamespace ns1 = factory.createOMNamespace("bar","x");
       OMElement root = factory.createOMElement("root",ns1);

       OMNamespace ns2 = root.declareNamespace("bar","y");

       OMElement elt1 = factory.createOMElement("foo",ns1);
       OMElement elt2 = factory.createOMElement("yuck",ns2);


       OMText txt1 = factory.createText(elt2,"blah");

       elt2.addChild(txt1);
       elt1.addChild(elt2);
       root.addChild(elt1);

       SimpleOMSerializer serializer = new SimpleOMSerializer();
       serializer.serialize(root, writer);

And the resulting output

<x:root xmlns:x="bar" xmlns:y="bar">
 <x:foo>
     <y:yuck>blah</y:yuck>
  </x:foo>
</x:root>

I guess this is better than the earlier one but note that you have to
EXPLICITLY declare the namespace!. What I meant to show you guys is
that even when you don't declare the namespaces this way, it is better
if we can have the same serialization. Otherwise if we have more
elements we will probably see XML's like the following (if the
declarenamespace method is NOT used).

<x:root xmlns:x="bar">
<x:foo2>
 <y:yuck xmlns:y="bar"></y:yuck>
</x:foo2>
<x:foo1>
 <y:yuck xmlns:y="bar"></y:yuck>
</x:foo1>
</x:root>

Of course this is perfectly valid but if we can push the 'y' namespace
declaration up the tree it will be better. Currently the serializer
does not try to optimize the namespace declarations.

thoughts ?

-- 
Ajith Ranabahu

Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Ajith Ranabahu wrote:

>Hi all,
>Since there was discussions going down to the code level I guess it
>will be beneficial for all to see how the things would be done with
>the current implementation and give you guys a taste of the code.
>
>        OMFactory factory = OMFactory.newInstance();
>        OMNamespace ns1 = factory.createOMNamespace("bar","x");
>        OMNamespace ns2 = factory.createOMNamespace("bar","y");
>
>        OMElement elt1 = factory.createOMElement("foo",ns1);
>        OMElement elt2 = factory.createOMElement("yuck",ns2);
>
>        OMText txt1 = factory.createText(elt2,"blah");
>
>        elt1.addChild(elt2);
>        elt2.addChild(txt1);
>
>        SimpleOMSerializer serializer = new SimpleOMSerializer();
>        serializer.serialize(elt1, writer);
>
>This is the produced serialization
>
><x:foo xmlns:x="bar">
>   <y:yuck xmlns:y="bar">blah</y:yuck>
></x:foo>
>
>I guess it is desirable to have the y namespace declared in the root
>element but the serializer does the namespace serialization only when
>it encounters the prefix for the first time.
>  
>
so there is no declareNamespace() functionality?

XmlPull (setPrefix() call) and i think StAX serializer allows to 
exlicitly request writing namespace declaration (xmlns:prefix='...') so 
if element has namespace declarations aattached it should be easy to 
make serializer to write them?

thanks,

alek

-- 
The best way to predict the future is to invent it - Alan Kay


Re: [Axis2] Namespace serialization problem

Posted by Ajith Ranabahu <aj...@gmail.com>.
Hi all,
Since there was discussions going down to the code level I guess it
will be beneficial for all to see how the things would be done with
the current implementation and give you guys a taste of the code.

        OMFactory factory = OMFactory.newInstance();
        OMNamespace ns1 = factory.createOMNamespace("bar","x");
        OMNamespace ns2 = factory.createOMNamespace("bar","y");

        OMElement elt1 = factory.createOMElement("foo",ns1);
        OMElement elt2 = factory.createOMElement("yuck",ns2);

        OMText txt1 = factory.createText(elt2,"blah");

        elt1.addChild(elt2);
        elt2.addChild(txt1);

        SimpleOMSerializer serializer = new SimpleOMSerializer();
        serializer.serialize(elt1, writer);

This is the produced serialization

<x:foo xmlns:x="bar">
   <y:yuck xmlns:y="bar">blah</y:yuck>
</x:foo>

I guess it is desirable to have the y namespace declared in the root
element but the serializer does the namespace serialization only when
it encounters the prefix for the first time.
-- 
Ajith Ranabahu

Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Sanjiva Weerawarana wrote:

>"Aleksander Slominski" <as...@cs.indiana.edu> writes:
>  
>
>>no - it has namespace but it is not declared.
>>    
>>
>
>True, but .. if you serialize that freshly created element the
>declaration better show up.
>
>  
>
this or you get error depending on how StAX serializer is configured

>>>Since the node isn't parented yet you
>>>can't go searning up the tree yet .. so are you suggesting that that
>>>search occur at the point of being added as a child of another element?
>>> 
>>>
>>>      
>>>
>>no need for search - validation can be done on demand or duing 
>>serialization.
>>    
>>
>
>It seems to me that if the user declares a namespace explicitly
>then that needs to be respected. However, if they just create an
>element by giving a QName (or its parts) or a OMNamespace node 
>then we have the resp. of creating the NS declaration.
>
>  
>
i do not agree - XML tree creation is done in chunks and i do not want 
OM to add declarations that are not needed.

>>>BTW we still retain
>>>   builder.newElement (String namespaceName, String localName)
>>>right??
>>> 
>>>
>>>      
>>>
>>i do not like strings what about
>>
>>    builder.newElement (String localName, String namespaceName)
>>    
>>
>
>Maybe I need glasses? These look very similar to me ;-).
>  
>
for Java compiler they are the same :)

>  
>
>>namespace delcarations should not be touched otherwise we may mess up 
>>XML c14n and signatures ...
>>    
>>
>
>Yes very good point. So let's be precise- suppose we're trying to read
>in the following:
>    <x:foo xmlns:x="bar" xmlns:y="bar">
>      <y:zzz/>
>      <yuck>blah</yuck>
>    </x:foo>
>
>What calls would I make to make the structure so that it'll roundtrip
>correctly?
>  
>
final static OmNamespace NS_X = builder.newNamespaces("bar", "x");
final static OmNamespace NS_Y = builder.newNamespaces("bar", "y");


OmElement foo = builder.newElement(NS_X, "foo");
foo.declareNamespace(NS_X);
foo.declareNamespace(NS_Y);
foo.addElement(NS_Y, "zzz");
foo.addElement("yuck").setText("blah");

note that if namespaces were not declared serializer can still use 
element OmNamespace to use correct prefix but foo would not have xmlns:y 
declared i.e. serialization would be:

    <x:foo xmlns:x="bar">
      <y:zzz xmlns:y="bar" />
      <yuck>blah</yuck>
    </x:foo>

i hope now it is clear where i am heading with ns handling.

thanks,

alek

-- 
The best way to predict the future is to invent it - Alan Kay


Re: [Axis2] Namespace serialization problem

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
"Aleksander Slominski" <as...@cs.indiana.edu> writes:
> no - it has namespace but it is not declared.

True, but .. if you serialize that freshly created element the
declaration better show up.

> >Since the node isn't parented yet you
> >can't go searning up the tree yet .. so are you suggesting that that
> >search occur at the point of being added as a child of another element?
> >  
> >
> no need for search - validation can be done on demand or duing 
> serialization.

It seems to me that if the user declares a namespace explicitly
then that needs to be respected. However, if they just create an
element by giving a QName (or its parts) or a OMNamespace node 
then we have the resp. of creating the NS declaration.

> >BTW we still retain
> >    builder.newElement (String namespaceName, String localName)
> >right??
> >  
> >
> i do not like strings what about
> 
>     builder.newElement (String localName, String namespaceName)

Maybe I need glasses? These look very similar to me ;-).

> namespace delcarations should not be touched otherwise we may mess up 
> XML c14n and signatures ...

Yes very good point. So let's be precise- suppose we're trying to read
in the following:
    <x:foo xmlns:x="bar" xmlns:y="bar">
      <y:zzz/>
      <yuck>blah</yuck>
    </x:foo>

What calls would I make to make the structure so that it'll roundtrip
correctly?

Sanjiva.


Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Sanjiva Weerawarana wrote:

>Guys, please remove unnecessary old stuff before replying .. makes
>it easier to follow a thread. Thanks!!
>
>"Aleksander Slominski" <as...@cs.indiana.edu> writes:
>  
>
>>>[Chinthaka] In this situation, in the constructor of the OMElement, we
>>>      
>>>
>have
>  
>
>>>to check whether the given OMNamespace is in the scope. If not, put it in
>>>the declared list.
>>>
>>>
>>>
>>>      
>>>
>>i think you do not need to do this. user may want to add namespace
>>declaration later on parent etc.
>>
>>i think auto-adding of namespace declarations is almost never good idea.
>>    
>>
>
>Wait I'm confused. If you say builder.newElement (NS, localName)
>then the new element *better* have the namespace declared or
>its wrong XML+Namespaces.
>
>Right??
>  
>
no - it has namespace but it is not declared.

during XML Infoset tree buildign it is expected that it is incomplete 
and invalid - in this  example element is created but element itslef is 
useless in XML it maust be places inside XML Document Information Item 
or other eii and only then it can be validated.

>So the element node has to include this NS declaration, unless the same
>NS node exists "up the tree." 
>
exactly

>Since the node isn't parented yet you
>can't go searning up the tree yet .. so are you suggesting that that
>search occur at the point of being added as a child of another element?
>  
>
no need for search - validation can be done on demand or duing 
serialization.


>BTW we still retain
>    builder.newElement (String namespaceName, String localName)
>right??
>  
>
i do not like strings what about

    builder.newElement (String localName, String namespaceName)


>  
>
>>>[Chinthaka] Sorry I've done a mistake. localName should be given. But not
>>>the namespace. Sorry for not putting ideas, correctly in to the paper :(
>>>
>>>
>>>      
>>>
>>those are just idea and i think it is good to discuss them even if they
>>are not finished or polished ;-)
>>
>>if element has localName but no namespace when it is created and user
>>needs to call createNamespace() and then setNamespace() it makes API
>>harder to use than simple: newElement(builder.newNamespace(
>>"http://chinthaka.org", "myPrefix" ), "localName")) which creates
>>element with correct namespace and localName and leaves option that
>>namespace may be already declared on parent (but that may be only
>>visible when this element is added to parent as a child)
>>    
>>
>
>Even if its declared on the parent the user may have re-declared it.
>Do we want to "clean up" the XML in that case and remove redundant
>NS declarations?? Round-tripping would suffer, of course.
>  
>
namespace delcarations should not be touched otherwise we may mess up 
XML c14n and signatures ...

alek

-- 
The best way to predict the future is to invent it - Alan Kay


Re: [Axis2] Namespace serialization problem

Posted by Sanjiva Weerawarana <sa...@opensource.lk>.
Guys, please remove unnecessary old stuff before replying .. makes
it easier to follow a thread. Thanks!!

"Aleksander Slominski" <as...@cs.indiana.edu> writes:
> > [Chinthaka] In this situation, in the constructor of the OMElement, we
have
> >to check whether the given OMNamespace is in the scope. If not, put it in
> >the declared list.
> >
> >
> >
> i think you do not need to do this. user may want to add namespace
> declaration later on parent etc.
>
> i think auto-adding of namespace declarations is almost never good idea.

Wait I'm confused. If you say builder.newElement (NS, localName)
then the new element *better* have the namespace declared or
its wrong XML+Namespaces.

Right??

So the element node has to include this NS declaration, unless the same
NS node exists "up the tree." Since the node isn't parented yet you
can't go searning up the tree yet .. so are you suggesting that that
search occur at the point of being added as a child of another element?

BTW we still retain
    builder.newElement (String namespaceName, String localName)
right??

> >[Chinthaka] Sorry I've done a mistake. localName should be given. But not
> >the namespace. Sorry for not putting ideas, correctly in to the paper :(
> >
> >
> those are just idea and i think it is good to discuss them even if they
> are not finished or polished ;-)
>
> if element has localName but no namespace when it is created and user
> needs to call createNamespace() and then setNamespace() it makes API
> harder to use than simple: newElement(builder.newNamespace(
> "http://chinthaka.org", "myPrefix" ), "localName")) which creates
> element with correct namespace and localName and leaves option that
> namespace may be already declared on parent (but that may be only
> visible when this element is added to parent as a child)

Even if its declared on the parent the user may have re-declared it.
Do we want to "clean up" the XML in that case and remove redundant
NS declarations?? Round-tripping would suffer, of course.

Sanjiva.


Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Eran Chinthaka wrote:

>>>Eran Chinthaka wrote:
>>>
>>>      
>>>
>>>>        
>>>>
>>>>>>Eran Chinthaka wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>OK , let me tell this from the scratch.
>>>>>>>
>>>>>>>No Namespace can exist without an Element.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>namespace can be attached to attribute too
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>[Chinthaka] What I meant here was that, namespace must be *declared* in
>>>>        
>>>>
>>>an
>>>      
>>>
>>>>element. Yeah, its true it may not be used for an element localname, and
>>>>will be used only for attributes.
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>>>So lets remove createOMNamespace and one can only "declare" a
>>>>>>>              
>>>>>>>
>>>namespace
>>>      
>>>
>>>>>>>              
>>>>>>>
>>>>>>in
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>an OMElement.
>>>>>>>
>>>>>>>The next place we want to have OMNamespace is the OMELement creation
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>part.
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>Here its bit tricky here. For me its like chicken and egg problem.
>>>>>>>
>>>>>>><myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>>>>>>>
>>>>>>>How can we do this ?
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>OmNamespace NS = builder.newNamespace(new URI("http://chinthaka.org",
>>>>>>"myPrefix");
>>>>>>builder,newFragment(NS, "name")
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>[Chinthaka] Alek, I didn't get this point.
>>>>
>>>>
>>>>        
>>>>
>>>let me rework code fragment to demonstrate how this can be done - by
>>>separating namespace creation from element code is simple:
>>>
>>>// namespace is created
>>>OmNamespace NS = builder.newNamespace(
>>>	new URI("http://chinthaka.org"),"myPrefix");
>>>
>>>// later namespace is used to create element representing:
>>>
>>>//<myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>>>
>>>...
>>>
>>>OmElement el = builder.newElement(NS, "name")
>>>      
>>>
>
> [Chinthaka] In this situation, in the constructor of the OMElement, we have
>to check whether the given OMNamespace is in the scope. If not, put it in
>the declared list.
>
>  
>
i think you do not need to do this. user may want to add namespace 
declaration later on parent etc.

i think auto-adding of namespace declarations is almost never good idea.

>>>      
>>>
>>>>        
>>>>
>>>>>>>If we are not allowing to create an OMNamespace, then this should be
>>>>>>>              
>>>>>>>
>>>like
>>>      
>>>
>>>>>>>OMElement element = factory.createOMElement(parent);
>>>>>>>OMNamespace ns = element.declareNamespace("http://chinthaka.org",
>>>>>>>"myPrefix");
>>>>>>>element.setNamespace(ns);
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>too complicated and not intuitive
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>[Chinthaka] Oops, I wonder why u say so.
>>>>We first define the element. Then set the namespace. Whats wrong with
>>>>        
>>>>
>>>that
>>>      
>>>
>>>>??
>>>>
>>>>
>>>>        
>>>>
>>>when you create element you want to give it name (missing in your
>>>example). i do not like that element may be in "intermediate" state when
>>>it has no name or no namespace but such "incomplete" element can be used
>>>- makes API harder to use.
>>>      
>>>
>
>[Chinthaka] Sorry I've done a mistake. localName should be given. But not
>the namespace. Sorry for not putting ideas, correctly in to the paper :(
>  
>
those are just idea and i think it is good to discuss them even if they 
are not finished or polished ;-)

if element has localName but no namespace when it is created and user 
needs to call createNamespace() and then setNamespace() it makes API 
harder to use than simple: newElement(builder.newNamespace( 
"http://chinthaka.org", "myPrefix" ), "localName")) which creates 
element with correct namespace and localName and leaves option that 
namespace may be already declared on parent (but that may be only 
visible when this element is added to parent as a child)


alek

>Thankx,
>Eran Chinthaka
>
>  
>
>>>>        
>>>>
>>>>>>>within the declareNamespace(), we first check for a namespace, in the
>>>>>>>already declared list. If found return that or else create new one.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>OmNamespace used for declareNamespace must have prefix!=null
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>[Chinthaka] Sorry what I meant here from declareNamespace() was that
>>>>declareNamespace(prefix,uri). Sorry abt that :(
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>>other possibility is that if it ns already declared it should be
>>>>>>exception but only if prefix is the same as of already existing
>>>>>>            
>>>>>>
>>>namespace?
>>>      
>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>I think this will solve the problem.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>i am not sure about that. i think creating namespaces in factory is
>>>>>>better as they are really constants (value objects) so can be shared in
>>>>>>any XML tree even over multiple threads
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>[Chinthaka] I think what u suggest is a global namespace table.
>>>>
>>>>        
>>>>
>>>it is decided in builder/factory implementation - there can be many
>>>implementations
>>>
>>>      
>>>
>>>>But still
>>>>we need to have namespace information within an element.
>>>>
>>>>
>>>>        
>>>>
>>>by reference
>>>
>>>      
>>>
>>>>I agree that even though this approach the extra global table, if one try
>>>>        
>>>>
>>>to
>>>      
>>>
>>>>declare the same namespace in two different places, he will get the same
>>>>object. Isn't it ?
>>>>
>>>>
>>>>        
>>>>
>>>no need for global table if you do not need it. builder/factory can
>>>still do new OmNamespaceImpl() if it want.
>>>
>>>      
>>>
>>>>I think that's good idea. But we have to make sure OMNamespace is
>>>>        
>>>>
>>>immutable.
>>>      
>>>
>>>>        
>>>>
>>>that is exactly what i am trying to suggest :)
>>>
>>>      
>>>
>>>>        
>>>>
>>>>>>            
>>>>>>
>>>>>>>Comments ??
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>main advantage of using immutable value objects as described in details
>>>>>>by Joshua Bloch in /Effective Java/: "C/lasses should be immutable
>>>>>>unless there's a very good reason to make them mutable/..../If a class
>>>>>>cannot be made immutable, you should still limit its mutability as much
>>>>>>as possible/." (see more in http://www.javapractices.com/Topic29.cjp
>>>>>>            
>>>>>>
>>>and
>>>      
>>>
>>>>>>i recommend reading this book)
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>[Chinthaka] Thankx for the reference. :)
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>it is good book for anybody designing Java API or library.
>>>
>>>thanks,
>>>
>>>alek
>>>
>>>      
>>>
>>>>Thankx,
>>>>Eran Chinthaka
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>>thanks,
>>>>>>
>>>>>>alek
>>>>>>
>>>>>>--
>>>>>>The best way to predict the future is to invent it - Alan Kay
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>--
>>>The best way to predict the future is to invent it - Alan Kay
>>>      
>>>
>
>
>
>  
>


-- 
The best way to predict the future is to invent it - Alan Kay


RE: [Axis2] Namespace serialization problem

Posted by Eran Chinthaka <ch...@opensource.lk>.
>>
>>Eran Chinthaka wrote:
>>
>>>
>>>
>>>>>Eran Chinthaka wrote:
>>>>>
>>>>>
>>>>>
>>>>>>OK , let me tell this from the scratch.
>>>>>>
>>>>>>No Namespace can exist without an Element.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>namespace can be attached to attribute too
>>>>>
>>>>>
>>>
>>>[Chinthaka] What I meant here was that, namespace must be *declared* in
>>an
>>>element. Yeah, its true it may not be used for an element localname, and
>>>will be used only for attributes.
>>>
>>>
>>>
>>>>>>So lets remove createOMNamespace and one can only "declare" a
>>namespace
>>>>>>
>>>>>>
>>>>>in
>>>>>
>>>>>
>>>>>>an OMElement.
>>>>>>
>>>>>>The next place we want to have OMNamespace is the OMELement creation
>>>>>>
>>>>>>
>>>>>part.
>>>>>
>>>>>
>>>>>>Here its bit tricky here. For me its like chicken and egg problem.
>>>>>>
>>>>>><myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>>>>>>
>>>>>>How can we do this ?
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>OmNamespace NS = builder.newNamespace(new URI("http://chinthaka.org",
>>>>>"myPrefix");
>>>>>builder,newFragment(NS, "name")
>>>>>
>>>>>
>>>
>>>[Chinthaka] Alek, I didn't get this point.
>>>
>>>
>>let me rework code fragment to demonstrate how this can be done - by
>>separating namespace creation from element code is simple:
>>
>>// namespace is created
>>OmNamespace NS = builder.newNamespace(
>>	new URI("http://chinthaka.org"),"myPrefix");
>>
>>// later namespace is used to create element representing:
>>
>>//<myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>>
>>...
>>
>>OmElement el = builder.newElement(NS, "name")

 [Chinthaka] In this situation, in the constructor of the OMElement, we have
to check whether the given OMNamespace is in the scope. If not, put it in
the declared list.

>>
>>
>>>
>>>
>>>>>>If we are not allowing to create an OMNamespace, then this should be
>>like
>>>>>>OMElement element = factory.createOMElement(parent);
>>>>>>OMNamespace ns = element.declareNamespace("http://chinthaka.org",
>>>>>>"myPrefix");
>>>>>>element.setNamespace(ns);
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>too complicated and not intuitive
>>>>>
>>>>>
>>>
>>> [Chinthaka] Oops, I wonder why u say so.
>>>We first define the element. Then set the namespace. Whats wrong with
>>that
>>>??
>>>
>>>
>>when you create element you want to give it name (missing in your
>>example). i do not like that element may be in "intermediate" state when
>>it has no name or no namespace but such "incomplete" element can be used
>>- makes API harder to use.

[Chinthaka] Sorry I've done a mistake. localName should be given. But not
the namespace. Sorry for not putting ideas, correctly in to the paper :(

Thankx,
Eran Chinthaka

>>
>>>
>>>
>>>>>>within the declareNamespace(), we first check for a namespace, in the
>>>>>>already declared list. If found return that or else create new one.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>OmNamespace used for declareNamespace must have prefix!=null
>>>>>
>>>>>
>>>
>>> [Chinthaka] Sorry what I meant here from declareNamespace() was that
>>>declareNamespace(prefix,uri). Sorry abt that :(
>>>
>>>
>>>
>>>>>other possibility is that if it ns already declared it should be
>>>>>exception but only if prefix is the same as of already existing
>>namespace?
>>>>>
>>>>>
>>>>>
>>>>>>I think this will solve the problem.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>i am not sure about that. i think creating namespaces in factory is
>>>>>better as they are really constants (value objects) so can be shared in
>>>>>any XML tree even over multiple threads
>>>>>
>>>>>
>>>
>>> [Chinthaka] I think what u suggest is a global namespace table.
>>>
>>it is decided in builder/factory implementation - there can be many
>>implementations
>>
>>>But still
>>>we need to have namespace information within an element.
>>>
>>>
>>by reference
>>
>>>I agree that even though this approach the extra global table, if one try
>>to
>>>declare the same namespace in two different places, he will get the same
>>>object. Isn't it ?
>>>
>>>
>>no need for global table if you do not need it. builder/factory can
>>still do new OmNamespaceImpl() if it want.
>>
>>>I think that's good idea. But we have to make sure OMNamespace is
>>immutable.
>>>
>>>
>>that is exactly what i am trying to suggest :)
>>
>>>
>>>
>>>>>
>>>>>
>>>>>>Comments ??
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>main advantage of using immutable value objects as described in details
>>>>>by Joshua Bloch in /Effective Java/: "C/lasses should be immutable
>>>>>unless there's a very good reason to make them mutable/..../If a class
>>>>>cannot be made immutable, you should still limit its mutability as much
>>>>>as possible/." (see more in http://www.javapractices.com/Topic29.cjp
>>and
>>>>>i recommend reading this book)
>>>>>
>>>>>
>>>
>>> [Chinthaka] Thankx for the reference. :)
>>>
>>>
>>>
>>>
>>it is good book for anybody designing Java API or library.
>>
>>thanks,
>>
>>alek
>>
>>>Thankx,
>>>Eran Chinthaka
>>>
>>>
>>>
>>>>>thanks,
>>>>>
>>>>>alek
>>>>>
>>>>>--
>>>>>The best way to predict the future is to invent it - Alan Kay
>>>>>
>>>>>
>>>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>>--
>>The best way to predict the future is to invent it - Alan Kay




Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Eran Chinthaka wrote:

>  
>
>>>Eran Chinthaka wrote:
>>>
>>>      
>>>
>>>>OK , let me tell this from the scratch.
>>>>
>>>>No Namespace can exist without an Element.
>>>>
>>>>
>>>>        
>>>>
>>>namespace can be attached to attribute too
>>>      
>>>
>
>[Chinthaka] What I meant here was that, namespace must be *declared* in an
>element. Yeah, its true it may not be used for an element localname, and
>will be used only for attributes.
>
>  
>
>>>>So lets remove createOMNamespace and one can only "declare" a namespace
>>>>        
>>>>
>>>in
>>>      
>>>
>>>>an OMElement.
>>>>
>>>>The next place we want to have OMNamespace is the OMELement creation
>>>>        
>>>>
>>>part.
>>>      
>>>
>>>>Here its bit tricky here. For me its like chicken and egg problem.
>>>>
>>>><myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>>>>
>>>>How can we do this ?
>>>>
>>>>
>>>>        
>>>>
>>>OmNamespace NS = builder.newNamespace(new URI("http://chinthaka.org",
>>>"myPrefix");
>>>builder,newFragment(NS, "name")
>>>      
>>>
>
>[Chinthaka] Alek, I didn't get this point.
>  
>
let me rework code fragment to demonstrate how this can be done - by 
separating namespace creation from element code is simple:

// namespace is created
OmNamespace NS = builder.newNamespace(
	new URI("http://chinthaka.org"),"myPrefix");

// later namespace is used to create element representing:

//<myPrefix:name xmlns:myPrefix="http://chinthaka.org">

...

OmElement el = builder.newElement(NS, "name")


>  
>
>>>>If we are not allowing to create an OMNamespace, then this should be like
>>>>OMElement element = factory.createOMElement(parent);
>>>>OMNamespace ns = element.declareNamespace("http://chinthaka.org",
>>>>"myPrefix");
>>>>element.setNamespace(ns);
>>>>
>>>>
>>>>        
>>>>
>>>too complicated and not intuitive
>>>      
>>>
>
> [Chinthaka] Oops, I wonder why u say so. 
>We first define the element. Then set the namespace. Whats wrong with that
>??
>  
>
when you create element you want to give it name (missing in your 
example). i do not like that element may be in "intermediate" state when 
it has no name or no namespace but such "incomplete" element can be used 
- makes API harder to use.

>  
>
>>>>within the declareNamespace(), we first check for a namespace, in the
>>>>already declared list. If found return that or else create new one.
>>>>
>>>>
>>>>        
>>>>
>>>OmNamespace used for declareNamespace must have prefix!=null
>>>      
>>>
>
> [Chinthaka] Sorry what I meant here from declareNamespace() was that
>declareNamespace(prefix,uri). Sorry abt that :(
>
>  
>
>>>other possibility is that if it ns already declared it should be
>>>exception but only if prefix is the same as of already existing namespace?
>>>
>>>      
>>>
>>>>I think this will solve the problem.
>>>>
>>>>
>>>>        
>>>>
>>>i am not sure about that. i think creating namespaces in factory is
>>>better as they are really constants (value objects) so can be shared in
>>>any XML tree even over multiple threads
>>>      
>>>
>
> [Chinthaka] I think what u suggest is a global namespace table. 
>
it is decided in builder/factory implementation - there can be many 
implementations

>But still
>we need to have namespace information within an element.
>  
>
by reference

>I agree that even though this approach the extra global table, if one try to
>declare the same namespace in two different places, he will get the same
>object. Isn't it ?
>  
>
no need for global table if you do not need it. builder/factory can 
still do new OmNamespaceImpl() if it want.

>I think that's good idea. But we have to make sure OMNamespace is immutable.
>  
>
that is exactly what i am trying to suggest :)

>  
>
>>>      
>>>
>>>>Comments ??
>>>>
>>>>
>>>>        
>>>>
>>>main advantage of using immutable value objects as described in details
>>>by Joshua Bloch in /Effective Java/: "C/lasses should be immutable
>>>unless there's a very good reason to make them mutable/..../If a class
>>>cannot be made immutable, you should still limit its mutability as much
>>>as possible/." (see more in http://www.javapractices.com/Topic29.cjp and
>>>i recommend reading this book)
>>>      
>>>
>
> [Chinthaka] Thankx for the reference. :)
>
>
>  
>
it is good book for anybody designing Java API or library.

thanks,

alek

>Thankx,
>Eran Chinthaka
>
>  
>
>>>thanks,
>>>
>>>alek
>>>
>>>--
>>>The best way to predict the future is to invent it - Alan Kay
>>>
>>>      
>>>
>
>
>
>  
>


-- 
The best way to predict the future is to invent it - Alan Kay


RE: [Axis2] Namespace serialization problem

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

>>
>>Eran Chinthaka wrote:
>>
>>>OK , let me tell this from the scratch.
>>>
>>>No Namespace can exist without an Element.
>>>
>>>
>>namespace can be attached to attribute too

[Chinthaka] What I meant here was that, namespace must be *declared* in an
element. Yeah, its true it may not be used for an element localname, and
will be used only for attributes.

>>
>>>So lets remove createOMNamespace and one can only "declare" a namespace
>>in
>>>an OMElement.
>>>
>>>The next place we want to have OMNamespace is the OMELement creation
>>part.
>>>Here its bit tricky here. For me its like chicken and egg problem.
>>>
>>><myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>>>
>>>How can we do this ?
>>>
>>>
>>OmNamespace NS = builder.newNamespace(new URI("http://chinthaka.org",
>>"myPrefix");
>>builder,newFragment(NS, "name")

[Chinthaka] Alek, I didn't get this point.

>>>If we are not allowing to create an OMNamespace, then this should be like
>>>OMElement element = factory.createOMElement(parent);
>>>OMNamespace ns = element.declareNamespace("http://chinthaka.org",
>>>"myPrefix");
>>>element.setNamespace(ns);
>>>
>>>
>>too complicated and not intuitive

 [Chinthaka] Oops, I wonder why u say so. 
We first define the element. Then set the namespace. Whats wrong with that
??

>>
>>>within the declareNamespace(), we first check for a namespace, in the
>>>already declared list. If found return that or else create new one.
>>>
>>>
>>OmNamespace used for declareNamespace must have prefix!=null

 [Chinthaka] Sorry what I meant here from declareNamespace() was that
declareNamespace(prefix,uri). Sorry abt that :(

>>
>>other possibility is that if it ns already declared it should be
>>exception but only if prefix is the same as of already existing namespace?
>>
>>>I think this will solve the problem.
>>>
>>>
>>i am not sure about that. i think creating namespaces in factory is
>>better as they are really constants (value objects) so can be shared in
>>any XML tree even over multiple threads

 [Chinthaka] I think what u suggest is a global namespace table. But still
we need to have namespace information within an element.
I agree that even though this approach the extra global table, if one try to
declare the same namespace in two different places, he will get the same
object. Isn't it ?
I think that's good idea. But we have to make sure OMNamespace is immutable.

>>
>>
>>>
>>>Comments ??
>>>
>>>
>>main advantage of using immutable value objects as described in details
>>by Joshua Bloch in /Effective Java/: "C/lasses should be immutable
>>unless there's a very good reason to make them mutable/..../If a class
>>cannot be made immutable, you should still limit its mutability as much
>>as possible/." (see more in http://www.javapractices.com/Topic29.cjp and
>>i recommend reading this book)

 [Chinthaka] Thankx for the reference. :)


Thankx,
Eran Chinthaka

>>
>>thanks,
>>
>>alek
>>
>>--
>>The best way to predict the future is to invent it - Alan Kay
>>




Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Eran Chinthaka wrote:

>OK , let me tell this from the scratch.
>
>No Namespace can exist without an Element. 
>  
>
namespace can be attached to attribute too

>So lets remove createOMNamespace and one can only "declare" a namespace in
>an OMElement.
>
>The next place we want to have OMNamespace is the OMELement creation part.
>Here its bit tricky here. For me its like chicken and egg problem.
>
><myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>
>How can we do this ?
>  
>
OmNamespace NS = builder.newNamespace(new URI("http://chinthaka.org", 
"myPrefix");
builder,newFragment(NS, "name")

>If we are not allowing to create an OMNamespace, then this should be like
>OMElement element = factory.createOMElement(parent);
>OMNamespace ns = element.declareNamespace("http://chinthaka.org",
>"myPrefix");
>element.setNamespace(ns);
>  
>
too complicated and not intuitive

>within the declareNamespace(), we first check for a namespace, in the
>already declared list. If found return that or else create new one.
>  
>
OmNamespace used for declareNamespace must have prefix!=null

other possibility is that if it ns already declared it should be 
exception but only if prefix is the same as of already existing namespace?

>I think this will solve the problem.
>  
>
i am not sure about that. i think creating namespaces in factory is 
better as they are really constants (value objects) so can be shared in 
any XML tree even over multiple threads


>
>Comments ??
>  
>
main advantage of using immutable value objects as described in details 
by Joshua Bloch in /Effective Java/: "C/lasses should be immutable 
unless there's a very good reason to make them mutable/..../If a class 
cannot be made immutable, you should still limit its mutability as much 
as possible/." (see more in http://www.javapractices.com/Topic29.cjp and 
i recommend reading this book)

thanks,

alek

-- 
The best way to predict the future is to invent it - Alan Kay


RE: [Axis2] Namespace serialization problem

Posted by Eran Chinthaka <ch...@opensource.lk>.
Let me do a small correction.

>>
>>OK , let me tell this from the scratch.
>>
>>No Namespace can exist without an Element.
>>
>>So lets remove createOMNamespace and one can only "declare" a namespace in
>>an OMElement.
>>
>>The next place we want to have OMNamespace is the OMELement creation part.
>>Here its bit tricky here. For me its like chicken and egg problem.
>>
>><myPrefix:name xmlns:myPrefix="http://chinthaka.org">
>>
>>How can we do this ?
>>
>>If we are not allowing to create an OMNamespace, then this should be like
>>OMElement element = factory.createOMElement(parent);
>>OMNamespace ns = element.declareNamespace("http://chinthaka.org",
>>"myPrefix");
>>element.setNamespace(ns);
>>
>>within the declareNamespace(), we first check for a namespace, in the
>>already declared list. If found return that or else create new one.

[Chinthaka] we first check the given namespace in the *inscope* namespace
list. If the namespace is available, just return that.
If not, add the new namespace to the declared namespaces list of the element
and return a reference.
>>
>>I think this will solve the problem.
>>
>>
>>Comments ??
>>
>>Eran Chinthaka
>>
>>
>>




RE: [Axis2] Namespace serialization problem

Posted by Eran Chinthaka <ch...@opensource.lk>.
OK , let me tell this from the scratch.

No Namespace can exist without an Element. 

So lets remove createOMNamespace and one can only "declare" a namespace in
an OMElement.

The next place we want to have OMNamespace is the OMELement creation part.
Here its bit tricky here. For me its like chicken and egg problem.

<myPrefix:name xmlns:myPrefix="http://chinthaka.org">

How can we do this ?

If we are not allowing to create an OMNamespace, then this should be like
OMElement element = factory.createOMElement(parent);
OMNamespace ns = element.declareNamespace("http://chinthaka.org",
"myPrefix");
element.setNamespace(ns);

within the declareNamespace(), we first check for a namespace, in the
already declared list. If found return that or else create new one.

I think this will solve the problem.


Comments ??

Eran Chinthaka




Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Srinath Perera wrote:

>>final static O,Namespace NS = fac.createOMNamespace("http://localhost/my","my");
>>
>>  // ...
>>
>>  OmElement method =  builder.createOMElement(NS, "echoOMElement",) ;
>>  OMElement value =  method.addElement(NS, "myValue") ;
>>  value.replaceChildrenWithText("Isaac Assimov, the foundation Sega");
>>    
>>
>
>We handle the namespaces by keeping declared name spaces at each
>Element (to me this is a another *better* representation of the
>namespace Stack). If we use the approach suggested by above code when
>              method.addElement(NS, "myValue") ;
>is called the the code should search through the namespace lists in
>the hierarchy (parents) to decide does the namespace should be added
>to this elemnt namespace list.
>  
>
i think it does not need to be added by default.

user calls declareNamespace on element to add namespace declarations.

if builder/serializer is nice ti will declare namespaces when they are 
first used or if it is strict it will throw exception to indicate that 
namespace is missing declaration. why to make "auto-magic" solution of 
namespace auto-declaration?

>One way out is to  put createNS(..) to the element
>1)  name space is always associated with a element it declared, it
>make sense to put create Namespace() to the  element
>  
>
it should be possible to share namespaces class instance between 
multiple classes.

>2) that free us from the cleanup the Names later (searching through
>the hierarchy)
>  
>
what do you mean by clean up - why would i want to do it?

>3) we can one entry point to make NS
>  
>
i think about OmNamespace like String: it is value object easy to create 
but it is nice if builder/factory controls creation of namespaces so 
interning (like String.intern()) can be done automatically (and very 
efficient - similarly how strings can be shared).

thanks,

alek


-- 
The best way to predict the future is to invent it - Alan Kay


Re: [Axis2] Namespace serialization problem

Posted by Srinath Perera <he...@gmail.com>.
> final static O,Namespace NS = fac.createOMNamespace("http://localhost/my","my");
> 
>   // ...
> 
>   OmElement method =  builder.createOMElement(NS, "echoOMElement",) ;
>   OMElement value =  method.addElement(NS, "myValue") ;
>   value.replaceChildrenWithText("Isaac Assimov, the foundation Sega");

We handle the namespaces by keeping declared name spaces at each
Element (to me this is a another *better* representation of the
namespace Stack). If we use the approach suggested by above code when
              method.addElement(NS, "myValue") ;
is called the the code should search through the namespace lists in
the hierarchy (parents) to decide does the namespace should be added
to this elemnt namespace list.

One way out is to  put createNS(..) to the element
1)  name space is always associated with a element it declared, it
make sense to put create Namespace() to the  element
2) that free us from the cleanup the Names later (searching through
the hierarchy)
3) we can one entry point to make NS

Thanks
Srinath

Re: [Axis2] Namespace serialization problem

Posted by Dasarath Weeratunge <da...@yahoo.com>.
Hi

> i like to declare namespace as constant then reuse
> it and i like to 
> build elements directly
> 
> final static O,Namespace NS =
> fac.createOMNamespace("http://localhost/my","my");
>   

OM can handle this even at present, no problem there.

> >
> StAX and XmlPull serializers can do it automatically
> no need for OM to 
> do it ...
> 
> alek

Ajith are you using XmlPull/StAX serializer in your
code?

Dasarath




		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 


Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Ajith Ranabahu wrote:

>Hi all,
>When I was writing the serializers I came across the following
>problems (they are not actually problems but kind of confusing areas
>!) I am talking about serializing OM to TEXT!
>Anyway here is the problem.
>When you create the OMnodes in a jdom like manner (where there is no
>restriction to construction, you can just say new Node()) the
>namespace declarations get into a mess! Have a look at the following
>piece of code.(BTW this is an actual piece of code from a test class)
>
>  OMNamespace omNs = fac.createOMNamespace("http://localhost/my","my");
>  OMElement method =  fac.createOMElement("echoOMElement",omNs) ;
>  OMElement value =  fac.createOMElement("myValue",omNs) ;
>  
>
it seems value and method elements are disconnected? should not value be 
child of method?

>  value.setValue("Isaac Assimov, the foundation Sega");
>  method.addChild(value);
>
>in this case where should the namespace be declared? is it right to
>have it in the top most element ?
>  
>
i like to declare namespace as constant then reuse it and i like to 
build elements directly

final static O,Namespace NS = fac.createOMNamespace("http://localhost/my","my");
  
  // ...

  OmElement method =  builder.createOMElement(NS, "echoOMElement",) ;
  OMElement value =  method.addElement(NS, "myValue") ;
  value.replaceChildrenWithText("Isaac Assimov, the foundation Sega");


>And what should happen if I am to serialize only the value element ?
>Since this is quite messy I did not deal with it at creation but had a
>solution for it at the serialization. 
>
serializer will either declare namespace prefixes automatically or fail 
depending how it is set up - i see no problem here.

>(this is the approach Srinath
>refers to as "mess first and sweep later" :)).
>  
>
hmm: i prefer to call it creative disorder: one needs  chaos to create 
order out of it :)

>I keep a list of prefixes that has already being written and writes
>out the elements own namespace as well as the declared ones if they
>are already not written.
>  
>
StAX and XmlPull serializers can do it automatically no need for OM to 
do it ...

alek

>Here are some sample outputs
>---------------------------------------------------------------------------------------------------------------------
>Full Soap output of a sample SOAP document made to an OM.
><soapenv:Envelope
>xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
>   <soapenv:Header>
>       <wsa:MessageID
>soapenv:mustUnderstand="0">uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>
>       <wsa:To soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</wsa:To>
>       <wsa:From soapenv:mustUnderstand="0">
>           <wsa:Address
>xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing"
>xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
>       </wsa:From>
>   </soapenv:Header>
>   <soapenv:Body>
>       <axis2:echoVoid
>xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
>   </soapenv:Body>
></soapenv:Envelope>
>------------------------------------------------------------------------------------------------------------------------
>here is the body element(only) serialised
>------------------------------------------------------------------------------------------------------------------------
><soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>       <axis2:echoVoid
>xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
>   </soapenv:Body>
>----------------------------------------------------------------------------------------------------------------------
>
>So as you can see it provides the desired output eventhough the
>representation may be messy underneath (and probably not the most
>efficient)!
>
>Any thoughts in improving this?
>
>  
>


-- 
The best way to predict the future is to invent it - Alan Kay


Re: [Axis2] Namespace serialization problem

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Srinath Perera wrote:

>On Thu, 16 Dec 2004 10:09:50 +0600, Eran Chinthaka
><ch...@opensource.lk> wrote:
>  
>
>>>>Hi all,
>>>>When I was writing the serializers I came across the following
>>>>problems (they are not actually problems but kind of confusing areas
>>>>!) I am talking about serializing OM to TEXT!
>>>>Anyway here is the problem.
>>>>When you create the OMnodes in a jdom like manner (where there is no
>>>>restriction to construction, you can just say new Node()) the
>>>>namespace declarations get into a mess! Have a look at the following
>>>>piece of code.(BTW this is an actual piece of code from a test class)
>>>>
>>>> OMNamespace omNs = fac.createOMNamespace("http://localhost/my","my");
>>>> OMElement method =  fac.createOMElement("echoOMElement",omNs) ;
>>>> OMElement value =  fac.createOMElement("myValue",omNs) ;
>>>> value.setValue("Isaac Assimov, the foundation Sega");
>>>> method.addChild(value);
>>>>
>>>>        
>>>>
>>[Chinthaka] Wait a minute. I think createOMNamespace method should not be
>>there in the Factory.
>>It should only be in the OMElement interface.
>>
>>I think that will solve the problem.
>>
>>(BTW : Did I put the createOMNamespace in factory. If yes, I've done
>>something wrong. But I can't remember me doing that :()
>>    
>>
>
>I is there .. remove it :) it slove the pro I think :)
>  
>
IMHO namespace (and element) creation should be handled by 
builder/factory - it is the right place to pool resources such as 
OmNamespace instances.

thanks,

alek

-- 
The best way to predict the future is to invent it - Alan Kay


Re: [Axis2] Namespace serialization problem

Posted by Srinath Perera <he...@gmail.com>.
On Thu, 16 Dec 2004 10:09:50 +0600, Eran Chinthaka
<ch...@opensource.lk> wrote:
> 
> >>
> >>Hi all,
> >>When I was writing the serializers I came across the following
> >>problems (they are not actually problems but kind of confusing areas
> >>!) I am talking about serializing OM to TEXT!
> >>Anyway here is the problem.
> >>When you create the OMnodes in a jdom like manner (where there is no
> >>restriction to construction, you can just say new Node()) the
> >>namespace declarations get into a mess! Have a look at the following
> >>piece of code.(BTW this is an actual piece of code from a test class)
> >>
> >>  OMNamespace omNs = fac.createOMNamespace("http://localhost/my","my");
> >>  OMElement method =  fac.createOMElement("echoOMElement",omNs) ;
> >>  OMElement value =  fac.createOMElement("myValue",omNs) ;
> >>  value.setValue("Isaac Assimov, the foundation Sega");
> >>  method.addChild(value);
> >>
> 
> [Chinthaka] Wait a minute. I think createOMNamespace method should not be
> there in the Factory.
> It should only be in the OMElement interface.
> 
> I think that will solve the problem.
> 
> (BTW : Did I put the createOMNamespace in factory. If yes, I've done
> something wrong. But I can't remember me doing that :()

I is there .. remove it :) it slove the pro I think :)

RE: [Axis2] Namespace serialization problem

Posted by Eran Chinthaka <ch...@opensource.lk>.
>>
>>Hi all,
>>When I was writing the serializers I came across the following
>>problems (they are not actually problems but kind of confusing areas
>>!) I am talking about serializing OM to TEXT!
>>Anyway here is the problem.
>>When you create the OMnodes in a jdom like manner (where there is no
>>restriction to construction, you can just say new Node()) the
>>namespace declarations get into a mess! Have a look at the following
>>piece of code.(BTW this is an actual piece of code from a test class)
>>
>>  OMNamespace omNs = fac.createOMNamespace("http://localhost/my","my");
>>  OMElement method =  fac.createOMElement("echoOMElement",omNs) ;
>>  OMElement value =  fac.createOMElement("myValue",omNs) ;
>>  value.setValue("Isaac Assimov, the foundation Sega");
>>  method.addChild(value);
>>

[Chinthaka] Wait a minute. I think createOMNamespace method should not be
there in the Factory.
It should only be in the OMElement interface. 

I think that will solve the problem.

(BTW : Did I put the createOMNamespace in factory. If yes, I've done
something wrong. But I can't remember me doing that :()

>>in this case where should the namespace be declared? is it right to
>>have it in the top most element ?
>>And what should happen if I am to serialize only the value element ?
>>Since this is quite messy I did not deal with it at creation but had a
>>solution for it at the serialization. (this is the approach Srinath
>>refers to as "mess first and sweep later" :)).
>>I keep a list of prefixes that has already being written and writes
>>out the elements own namespace as well as the declared ones if they
>>are already not written.
>>
>>Here are some sample outputs
>>--------------------------------------------------------------------------
>>-------------------------------------------
>>Full Soap output of a sample SOAP document made to an OM.
>><soapenv:Envelope
>>xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>>xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
>>   <soapenv:Header>
>>       <wsa:MessageID
>>soapenv:mustUnderstand="0">uuid:920C5190-0B8F-11D9-8CED-
>>F22EDEEBF7E5</wsa:MessageID>
>>       <wsa:To
>>soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</w
>>sa:To>
>>       <wsa:From soapenv:mustUnderstand="0">
>>           <wsa:Address
>>xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing"
>>xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schemas.xm
>>lsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
>>       </wsa:From>
>>   </soapenv:Header>
>>   <soapenv:Body>
>>       <axis2:echoVoid
>>xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
>>   </soapenv:Body>
>></soapenv:Envelope>
>>--------------------------------------------------------------------------
>>----------------------------------------------
>>here is the body element(only) serialised
>>--------------------------------------------------------------------------
>>----------------------------------------------
>><soapenv:Body xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>>       <axis2:echoVoid
>>xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
>>   </soapenv:Body>
>>--------------------------------------------------------------------------
>>--------------------------------------------
>>
>>So as you can see it provides the desired output eventhough the
>>representation may be messy underneath (and probably not the most
>>efficient)!
>>
>>Any thoughts in improving this?
>>
>>--
>>Ajith Ranabahu




Re: [Axis2] Namespace serialization problem

Posted by Dasarath Weeratunge <da...@yahoo.com>.
Hi

>From what I remember, in that first implementation we
didn't have this problem because a Namespace was
always created using an OMElement. However, the
reference returned could be used in other elements as
well. Therefore when serializing, the problem of
deciding when to serialize the namespace did not
arise-- each OMElement had a list of namespace that
required serializing.

Now to the second problem. Yes, this is something
which I didn't address! +1 for your solution.

Dasarath


--- Ajith Ranabahu <aj...@gmail.com> wrote:

> Hi all,
> When I was writing the serializers I came across the
> following
> problems (they are not actually problems but kind of
> confusing areas
> !) I am talking about serializing OM to TEXT!
> Anyway here is the problem.
> When you create the OMnodes in a jdom like manner
> (where there is no
> restriction to construction, you can just say new
> Node()) the
> namespace declarations get into a mess! Have a look
> at the following
> piece of code.(BTW this is an actual piece of code
> from a test class)
> 
>   OMNamespace omNs =
> fac.createOMNamespace("http://localhost/my","my");
>   OMElement method = 
> fac.createOMElement("echoOMElement",omNs) ;
>   OMElement value = 
> fac.createOMElement("myValue",omNs) ;
>   value.setValue("Isaac Assimov, the foundation
> Sega");
>   method.addChild(value);
> 
> in this case where should the namespace be declared?
> is it right to
> have it in the top most element ?
> And what should happen if I am to serialize only the
> value element ?
> Since this is quite messy I did not deal with it at
> creation but had a
> solution for it at the serialization. (this is the
> approach Srinath
> refers to as "mess first and sweep later" :)).
> I keep a list of prefixes that has already being
> written and writes
> out the elements own namespace as well as the
> declared ones if they
> are already not written.
> 
> Here are some sample outputs
>
---------------------------------------------------------------------------------------------------------------------
> Full Soap output of a sample SOAP document made to
> an OM.
> <soapenv:Envelope
>
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/03/addressing">
>    <soapenv:Header>
>        <wsa:MessageID
>
soapenv:mustUnderstand="0">uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>
>        <wsa:To
>
soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</wsa:To>
>        <wsa:From soapenv:mustUnderstand="0">
>            <wsa:Address
>
xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing"
>
xmlns="http://schemas.xmlsoap.org/ws/2004/03/addressing">http://schemas.xmlsoap.org/ws/2004/03/addressing/role/anonymous</wsa:Address>
>        </wsa:From>
>    </soapenv:Header>
>    <soapenv:Body>
>        <axis2:echoVoid
>
xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
>    </soapenv:Body>
> </soapenv:Envelope>
>
------------------------------------------------------------------------------------------------------------------------
> here is the body element(only) serialised
>
------------------------------------------------------------------------------------------------------------------------
> <soapenv:Body
>
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
>        <axis2:echoVoid
>
xmlns:axis2="http://ws.apache.org/axis2"></axis2:echoVoid>
>    </soapenv:Body>
>
----------------------------------------------------------------------------------------------------------------------
> 
> So as you can see it provides the desired output
> eventhough the
> representation may be messy underneath (and probably
> not the most
> efficient)!
> 
> Any thoughts in improving this?
> 
> -- 
> Ajith Ranabahu
> 



		
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo