Web Interface and XML binding

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Web Interface and XML binding

NorbertHartl
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Jan van de Sandt
Hello Norbert,

I have developed some code to serialize object to XML and visa versa using their Magritte descriptions. It is not completely finished yet but for standard scenario's it works fine.

Here an example where an instance of MAXMLTestPerson is serialized to XML.

   <MAXMLTestPerson>
        <name>Bill Gates</name>
        <address>
            <MAXMLTestAddress>
                <city>Amsterdam</city>
                <street>Mainstreet</street>
            </MAXMLTestAddress>
        </address>
        <birthDate>1966-10-20</birthDate>
    </MAXMLTestPerson>

It can be de-serialized using MAXMLParser:

    MAXMLParser parse: self personWithAddressXML readStream.

The serialization process can be customized. I still have to add proper error handling. My intention was to add it to the Magritte add-ons repository when the error handling was fully working. If you want I can add it sooner so you can have a look.

Jan.




On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <[hidden email]> wrote:
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

NorbertHartl
Hi Jan,

that looks great. I really would like to have a look at the code. May I have a few questions upfront:

- I assume MAXMLTestPerson is the class name of the instance you are serializing. I would avoid exposing an implementation detail to the outside world. Do you use that information on parse time? I would expect that you know how to parse the top level object (by service context etc.). Regarding references the detail about what to parse is in MAReferenceDescription you are using for e.g. the address. If this is all right you could go with <Person> and <Address>. This would make it possible to parse the XML with a subclass of e.g. MAXMLTestPerson

- You inlined the address instance into the person. Is this exchangable? I'm not sure I'll go for REST but if yes then I would like to do it by reference. Let's say <adress id="http://my.service.srv/address/12345"> ...

- What do you do with the date field in birthday? Is this a fixed format or do you specify this over magritte?

Thanks,

Norbert


On 09.02.2010, at 11:59, Jan van de Sandt wrote:

Hello Norbert,

I have developed some code to serialize object to XML and visa versa using their Magritte descriptions. It is not completely finished yet but for standard scenario's it works fine.

Here an example where an instance of MAXMLTestPerson is serialized to XML.

   <MAXMLTestPerson>
        <name>Bill Gates</name>
        <address>
            <MAXMLTestAddress>
                <city>Amsterdam</city>
                <street>Mainstreet</street>
            </MAXMLTestAddress>
        </address>
        <birthDate>1966-10-20</birthDate>
    </MAXMLTestPerson>

It can be de-serialized using MAXMLParser:

    MAXMLParser parse: self personWithAddressXML readStream.

The serialization process can be customized. I still have to add proper error handling. My intention was to add it to the Magritte add-ons repository when the error handling was fully working. If you want I can add it sooner so you can have a look.

Jan.




On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <[hidden email]> wrote:
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Jan van de Sandt
Hello,

On Tue, Feb 9, 2010 at 12:23 PM, Norbert Hartl <[hidden email]> wrote:
Hi Jan,

that looks great. I really would like to have a look at the code. May I have a few questions upfront:

Ok, I will upload the code this evening.
 
- I assume MAXMLTestPerson is the class name of the instance you are serializing. I would avoid exposing an implementation detail to the outside world. Do you use that information on parse time? I would expect that you know how to parse the top level object (by service context etc.). Regarding references the detail about what to parse is in MAReferenceDescription you are using for e.g. the address. If this is all right you could go with <Person> and <Address>. This would make it possible to parse the XML with a subclass of e.g. MAXMLTestPerson

Yes MAXMLTestPerson is the class name. This was the easiest way to serialize instances of classes that have the same Magritte description. This behaviour is implemented in MAXMLWriter, a subclass of MAWriter. It can be easily customized by creating your own subclass of this visitor.

 
- You inlined the address instance into the person. Is this exchangable? I'm not sure I'll go for REST but if yes then I would like to do it by reference. Let's say <adress id="http://my.service.srv/address/12345"> ...

The current implementation inlines the first occurrence of an object and adds an id attribute. If an object occurs multiple times than a reference to the id is inlined. For example:

Smalltalk:

personWithFriendsCycle

    | bill john carl |
   
    bill := MAXMLTestPerson new
        name: 'Bill';
        yourself.
    john := MAXMLTestPerson new
        name: 'John';
        yourself.
    carl := MAXMLTestPerson new
        name: 'Carl';
        friends: (OrderedCollection with: bill with: john);
        yourself.
       
    bill friends: (OrderedCollection with: john with: carl).
    john friends: (OrderedCollection with: bill with: carl).
   
    ^carl

XML:

<MAXMLTestPerson id="1">
    <name>Carl</name>
    <friends>
        <OrderedCollection>
            <MAXMLTestPerson id="2">
                <name>Bill</name>
                <friends>
                    <OrderedCollection>
                        <MAXMLTestPerson id="3">
                            <name>John</name>
                            <friends>
                                <OrderedCollection>
                                    <MAXMLTestPerson ref="2"/>
                                    <MAXMLTestPerson ref="1"/>
                                </OrderedCollection>
                            </friends>
                        </MAXMLTestPerson>
                        <MAXMLTestPerson ref="1"/>
                    </OrderedCollection>
                </friends>
            </MAXMLTestPerson>
            <MAXMLTestPerson ref="3"/>
        </OrderedCollection>
    </friends>
</MAXMLTestPerson>

 
- What do you do with the date field in birthday? Is this a fixed format or do you specify this over magritte?

This is also implemented using the MAXMLWriter visitor and can be easily customized per description class.

Jan.
 


On 09.02.2010, at 11:59, Jan van de Sandt wrote:

Hello Norbert,

I have developed some code to serialize object to XML and visa versa using their Magritte descriptions. It is not completely finished yet but for standard scenario's it works fine.

Here an example where an instance of MAXMLTestPerson is serialized to XML.

   <MAXMLTestPerson>
        <name>Bill Gates</name>
        <address>
            <MAXMLTestAddress>
                <city>Amsterdam</city>
                <street>Mainstreet</street>
            </MAXMLTestAddress>
        </address>
        <birthDate>1966-10-20</birthDate>
    </MAXMLTestPerson>

It can be de-serialized using MAXMLParser:

    MAXMLParser parse: self personWithAddressXML readStream.

The serialization process can be customized. I still have to add proper error handling. My intention was to add it to the Magritte add-ons repository when the error handling was fully working. If you want I can add it sooner so you can have a look.

Jan.




On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <[hidden email]> wrote:
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Jan van de Sandt
Hello,

I have uploaded the package Magritte-XMLSupport to http://source.lukas-renggli.ch/magritteaddons. The package has a dependency on XMLParser from http://www.squeaksource.com/XMLSupport.

I have developed this package using "Magritte for Seaside 3.0". But is also works with "Magritte for Seaside 2.8", in this case you need to add the the Grease package from the Seaside 3.0 as an extra dependency.

Have a look at the unit tests to see how to use the package. Note that the API is not yet stable. I use it to export and import my Magritte domain objects in a readable format. I'm now working on export & import functionality for Pier using this library, this could lead to changes/improvements in the package API.

Jan.



On Tue, Feb 9, 2010 at 1:15 PM, Jan van de Sandt <[hidden email]> wrote:
Hello,

On Tue, Feb 9, 2010 at 12:23 PM, Norbert Hartl <[hidden email]> wrote:
Hi Jan,

that looks great. I really would like to have a look at the code. May I have a few questions upfront:

Ok, I will upload the code this evening.
 
- I assume MAXMLTestPerson is the class name of the instance you are serializing. I would avoid exposing an implementation detail to the outside world. Do you use that information on parse time? I would expect that you know how to parse the top level object (by service context etc.). Regarding references the detail about what to parse is in MAReferenceDescription you are using for e.g. the address. If this is all right you could go with <Person> and <Address>. This would make it possible to parse the XML with a subclass of e.g. MAXMLTestPerson

Yes MAXMLTestPerson is the class name. This was the easiest way to serialize instances of classes that have the same Magritte description. This behaviour is implemented in MAXMLWriter, a subclass of MAWriter. It can be easily customized by creating your own subclass of this visitor.

 
- You inlined the address instance into the person. Is this exchangable? I'm not sure I'll go for REST but if yes then I would like to do it by reference. Let's say <adress id="http://my.service.srv/address/12345"> ...

The current implementation inlines the first occurrence of an object and adds an id attribute. If an object occurs multiple times than a reference to the id is inlined. For example:

Smalltalk:

personWithFriendsCycle

    | bill john carl |
   
    bill := MAXMLTestPerson new
        name: 'Bill';
        yourself.
    john := MAXMLTestPerson new
        name: 'John';
        yourself.
    carl := MAXMLTestPerson new
        name: 'Carl';
        friends: (OrderedCollection with: bill with: john);
        yourself.
       
    bill friends: (OrderedCollection with: john with: carl).
    john friends: (OrderedCollection with: bill with: carl).
   
    ^carl

XML:

<MAXMLTestPerson id="1">
    <name>Carl</name>
    <friends>
        <OrderedCollection>
            <MAXMLTestPerson id="2">
                <name>Bill</name>
                <friends>
                    <OrderedCollection>
                        <MAXMLTestPerson id="3">
                            <name>John</name>
                            <friends>
                                <OrderedCollection>
                                    <MAXMLTestPerson ref="2"/>
                                    <MAXMLTestPerson ref="1"/>
                                </OrderedCollection>
                            </friends>
                        </MAXMLTestPerson>
                        <MAXMLTestPerson ref="1"/>
                    </OrderedCollection>
                </friends>
            </MAXMLTestPerson>
            <MAXMLTestPerson ref="3"/>
        </OrderedCollection>
    </friends>
</MAXMLTestPerson>

 
- What do you do with the date field in birthday? Is this a fixed format or do you specify this over magritte?

This is also implemented using the MAXMLWriter visitor and can be easily customized per description class.

Jan.
 


On 09.02.2010, at 11:59, Jan van de Sandt wrote:

Hello Norbert,

I have developed some code to serialize object to XML and visa versa using their Magritte descriptions. It is not completely finished yet but for standard scenario's it works fine.

Here an example where an instance of MAXMLTestPerson is serialized to XML.

   <MAXMLTestPerson>
        <name>Bill Gates</name>
        <address>
            <MAXMLTestAddress>
                <city>Amsterdam</city>
                <street>Mainstreet</street>
            </MAXMLTestAddress>
        </address>
        <birthDate>1966-10-20</birthDate>
    </MAXMLTestPerson>

It can be de-serialized using MAXMLParser:

    MAXMLParser parse: self personWithAddressXML readStream.

The serialization process can be customized. I still have to add proper error handling. My intention was to add it to the Magritte add-ons repository when the error handling was fully working. If you want I can add it sooner so you can have a look.

Jan.




On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <[hidden email]> wrote:
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

NorbertHartl
Hi,

On 09.02.2010, at 20:00, Jan van de Sandt wrote:

Hello,

I have uploaded the package Magritte-XMLSupport to http://source.lukas-renggli.ch/magritteaddons. The package has a dependency on XMLParser from http://www.squeaksource.com/XMLSupport.

thanks for sharing. I'll have some time this weekend to investigate this. 

I have developed this package using "Magritte for Seaside 3.0". But is also works with "Magritte for Seaside 2.8", in this case you need to add the the Grease package from the Seaside 3.0 as an extra dependency.

I don't think there is that much of a difference. I will see. As long as the pier2 for gemstone isn't ready I'll go with magritte for 2.8. Afterwards I'll port it. Than I'll see.

Have a look at the unit tests to see how to use the package. Note that the API is not yet stable. I use it to export and import my Magritte domain objects in a readable format. I'm now working on export & import functionality for Pier using this library, this could lead to changes/improvements in the package API.

Fair enough. I will start to plug it onto a HTTP Interface. I'll send you a status when I have something running.

Btw. how do you do object resolving? Or better do you assume that always the whole object graph is pulled in or is there an update of existing objects? 

Norbert

Jan.



On Tue, Feb 9, 2010 at 1:15 PM, Jan van de Sandt <[hidden email]> wrote:
Hello,

On Tue, Feb 9, 2010 at 12:23 PM, Norbert Hartl <[hidden email]> wrote:
Hi Jan,

that looks great. I really would like to have a look at the code. May I have a few questions upfront:

Ok, I will upload the code this evening.
 
- I assume MAXMLTestPerson is the class name of the instance you are serializing. I would avoid exposing an implementation detail to the outside world. Do you use that information on parse time? I would expect that you know how to parse the top level object (by service context etc.). Regarding references the detail about what to parse is in MAReferenceDescription you are using for e.g. the address. If this is all right you could go with <Person> and <Address>. This would make it possible to parse the XML with a subclass of e.g. MAXMLTestPerson

Yes MAXMLTestPerson is the class name. This was the easiest way to serialize instances of classes that have the same Magritte description. This behaviour is implemented in MAXMLWriter, a subclass of MAWriter. It can be easily customized by creating your own subclass of this visitor.

 
- You inlined the address instance into the person. Is this exchangable? I'm not sure I'll go for REST but if yes then I would like to do it by reference. Let's say <adress id="http://my.service.srv/address/12345"> ...

The current implementation inlines the first occurrence of an object and adds an id attribute. If an object occurs multiple times than a reference to the id is inlined. For example:

Smalltalk:

personWithFriendsCycle

    | bill john carl |
   
    bill := MAXMLTestPerson new
        name: 'Bill';
        yourself.
    john := MAXMLTestPerson new
        name: 'John';
        yourself.
    carl := MAXMLTestPerson new
        name: 'Carl';
        friends: (OrderedCollection with: bill with: john);
        yourself.
       
    bill friends: (OrderedCollection with: john with: carl).
    john friends: (OrderedCollection with: bill with: carl).
   
    ^carl

XML:

<MAXMLTestPerson id="1">
    <name>Carl</name>
    <friends>
        <OrderedCollection>
            <MAXMLTestPerson id="2">
                <name>Bill</name>
                <friends>
                    <OrderedCollection>
                        <MAXMLTestPerson id="3">
                            <name>John</name>
                            <friends>
                                <OrderedCollection>
                                    <MAXMLTestPerson ref="2"/>
                                    <MAXMLTestPerson ref="1"/>
                                </OrderedCollection>
                            </friends>
                        </MAXMLTestPerson>
                        <MAXMLTestPerson ref="1"/>
                    </OrderedCollection>
                </friends>
            </MAXMLTestPerson>
            <MAXMLTestPerson ref="3"/>
        </OrderedCollection>
    </friends>
</MAXMLTestPerson>

 
- What do you do with the date field in birthday? Is this a fixed format or do you specify this over magritte?

This is also implemented using the MAXMLWriter visitor and can be easily customized per description class.

Jan.
 


On 09.02.2010, at 11:59, Jan van de Sandt wrote:

Hello Norbert,

I have developed some code to serialize object to XML and visa versa using their Magritte descriptions. It is not completely finished yet but for standard scenario's it works fine.

Here an example where an instance of MAXMLTestPerson is serialized to XML.

   <MAXMLTestPerson>
        <name>Bill Gates</name>
        <address>
            <MAXMLTestAddress>
                <city>Amsterdam</city>
                <street>Mainstreet</street>
            </MAXMLTestAddress>
        </address>
        <birthDate>1966-10-20</birthDate>
    </MAXMLTestPerson>

It can be de-serialized using MAXMLParser:

    MAXMLParser parse: self personWithAddressXML readStream.

The serialization process can be customized. I still have to add proper error handling. My intention was to add it to the Magritte add-ons repository when the error handling was fully working. If you want I can add it sooner so you can have a look.

Jan.




On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <[hidden email]> wrote:
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Philippe Marschall
In reply to this post by NorbertHartl
2010/2/9 Norbert Hartl <[hidden email]>:
> Hi,
>
> at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.
>
> Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.
>
> I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

The AudioScrobbler [1] and TopFeeder [2] projects uses Magritte for
XML to object binding.

 [1] http://source.lukas-renggli.ch/audioscrobbler.html
 [2] http://source.lukas-renggli.ch/topfeeder.html

Cheers
Philippe

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

NorbertHartl
In reply to this post by Jan van de Sandt
Hi,

thanks for uploading. I had some time to take a look. Do you know SIXX?


This is also about complete object graph serialization/deserialization and has been ported to most of the smalltalk dialects. I does not depend on magritte. I used this to transfer my objects from my squeak deployment into the new gemstone deployment. I can imagine that you can offer another level of control of the serialization/deserialization process. But I'm looking for something much more simple.

thanks very much,

Norbert


On 09.02.2010, at 20:00, Jan van de Sandt wrote:

Hello,

I have uploaded the package Magritte-XMLSupport to http://source.lukas-renggli.ch/magritteaddons. The package has a dependency on XMLParser from http://www.squeaksource.com/XMLSupport.

I have developed this package using "Magritte for Seaside 3.0". But is also works with "Magritte for Seaside 2.8", in this case you need to add the the Grease package from the Seaside 3.0 as an extra dependency.

Have a look at the unit tests to see how to use the package. Note that the API is not yet stable. I use it to export and import my Magritte domain objects in a readable format. I'm now working on export & import functionality for Pier using this library, this could lead to changes/improvements in the package API.

Jan.



On Tue, Feb 9, 2010 at 1:15 PM, Jan van de Sandt <[hidden email]> wrote:
Hello,

On Tue, Feb 9, 2010 at 12:23 PM, Norbert Hartl <[hidden email]> wrote:
Hi Jan,

that looks great. I really would like to have a look at the code. May I have a few questions upfront:

Ok, I will upload the code this evening.
 
- I assume MAXMLTestPerson is the class name of the instance you are serializing. I would avoid exposing an implementation detail to the outside world. Do you use that information on parse time? I would expect that you know how to parse the top level object (by service context etc.). Regarding references the detail about what to parse is in MAReferenceDescription you are using for e.g. the address. If this is all right you could go with <Person> and <Address>. This would make it possible to parse the XML with a subclass of e.g. MAXMLTestPerson

Yes MAXMLTestPerson is the class name. This was the easiest way to serialize instances of classes that have the same Magritte description. This behaviour is implemented in MAXMLWriter, a subclass of MAWriter. It can be easily customized by creating your own subclass of this visitor.

 
- You inlined the address instance into the person. Is this exchangable? I'm not sure I'll go for REST but if yes then I would like to do it by reference. Let's say <adress id="http://my.service.srv/address/12345"> ...

The current implementation inlines the first occurrence of an object and adds an id attribute. If an object occurs multiple times than a reference to the id is inlined. For example:

Smalltalk:

personWithFriendsCycle

    | bill john carl |
   
    bill := MAXMLTestPerson new
        name: 'Bill';
        yourself.
    john := MAXMLTestPerson new
        name: 'John';
        yourself.
    carl := MAXMLTestPerson new
        name: 'Carl';
        friends: (OrderedCollection with: bill with: john);
        yourself.
       
    bill friends: (OrderedCollection with: john with: carl).
    john friends: (OrderedCollection with: bill with: carl).
   
    ^carl

XML:

<MAXMLTestPerson id="1">
    <name>Carl</name>
    <friends>
        <OrderedCollection>
            <MAXMLTestPerson id="2">
                <name>Bill</name>
                <friends>
                    <OrderedCollection>
                        <MAXMLTestPerson id="3">
                            <name>John</name>
                            <friends>
                                <OrderedCollection>
                                    <MAXMLTestPerson ref="2"/>
                                    <MAXMLTestPerson ref="1"/>
                                </OrderedCollection>
                            </friends>
                        </MAXMLTestPerson>
                        <MAXMLTestPerson ref="1"/>
                    </OrderedCollection>
                </friends>
            </MAXMLTestPerson>
            <MAXMLTestPerson ref="3"/>
        </OrderedCollection>
    </friends>
</MAXMLTestPerson>

 
- What do you do with the date field in birthday? Is this a fixed format or do you specify this over magritte?

This is also implemented using the MAXMLWriter visitor and can be easily customized per description class.

Jan.
 


On 09.02.2010, at 11:59, Jan van de Sandt wrote:

Hello Norbert,

I have developed some code to serialize object to XML and visa versa using their Magritte descriptions. It is not completely finished yet but for standard scenario's it works fine.

Here an example where an instance of MAXMLTestPerson is serialized to XML.

   <MAXMLTestPerson>
        <name>Bill Gates</name>
        <address>
            <MAXMLTestAddress>
                <city>Amsterdam</city>
                <street>Mainstreet</street>
            </MAXMLTestAddress>
        </address>
        <birthDate>1966-10-20</birthDate>
    </MAXMLTestPerson>

It can be de-serialized using MAXMLParser:

    MAXMLParser parse: self personWithAddressXML readStream.

The serialization process can be customized. I still have to add proper error handling. My intention was to add it to the Magritte add-ons repository when the error handling was fully working. If you want I can add it sooner so you can have a look.

Jan.




On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <[hidden email]> wrote:
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

NorbertHartl
In reply to this post by Philippe Marschall
Hi Philippe,

that is close to what I was searching for. I was glad to see that top feeder is using the audioscrobbler code (only a few tweaks). Did I miss somehting or is this just the parsing of the format?

The code does not seem to be audioscrobbler dependent. Is there a chance to rip the XML part out of the package? Adding a writer to this code base would already lead to a descent magritte XML handling as far as I could see from a short peek.

Norbert

On 09.02.2010, at 21:43, Philippe Marschall wrote:

> 2010/2/9 Norbert Hartl <[hidden email]>:
>> Hi,
>>
>> at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.
>>
>> Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.
>>
>> I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.
>
> The AudioScrobbler [1] and TopFeeder [2] projects uses Magritte for
> XML to object binding.
>
> [1] http://source.lukas-renggli.ch/audioscrobbler.html
> [2] http://source.lukas-renggli.ch/topfeeder.html
>
> Cheers
> Philippe
>
> _______________________________________________
> Magritte, Pier and Related Tools ...
> https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Jan van de Sandt
In reply to this post by NorbertHartl
Hi,

Yes, I know SIXX. I think it is well suited for serializing and de-serializing objects to XML. But the resulting XML will look a bit strange to non-smalltalkers, so for exchanging information with other platforms it is not the best solution I think.

I am now incorporating some of the ideas from XStream (http://xstream.codehaus.org/) into the MAXMLSupport library. This will offer a simple facade for the conversion and this facade can be used to configure the conversion to and from XML. For example by specifying aliases for elements.

Jan.

On Thu, Feb 11, 2010 at 9:25 PM, Norbert Hartl <[hidden email]> wrote:
Hi,

thanks for uploading. I had some time to take a look. Do you know SIXX?


This is also about complete object graph serialization/deserialization and has been ported to most of the smalltalk dialects. I does not depend on magritte. I used this to transfer my objects from my squeak deployment into the new gemstone deployment. I can imagine that you can offer another level of control of the serialization/deserialization process. But I'm looking for something much more simple.

thanks very much,

Norbert


On 09.02.2010, at 20:00, Jan van de Sandt wrote:

Hello,

I have uploaded the package Magritte-XMLSupport to http://source.lukas-renggli.ch/magritteaddons. The package has a dependency on XMLParser from http://www.squeaksource.com/XMLSupport.

I have developed this package using "Magritte for Seaside 3.0". But is also works with "Magritte for Seaside 2.8", in this case you need to add the the Grease package from the Seaside 3.0 as an extra dependency.

Have a look at the unit tests to see how to use the package. Note that the API is not yet stable. I use it to export and import my Magritte domain objects in a readable format. I'm now working on export & import functionality for Pier using this library, this could lead to changes/improvements in the package API.

Jan.



On Tue, Feb 9, 2010 at 1:15 PM, Jan van de Sandt <[hidden email]> wrote:
Hello,

On Tue, Feb 9, 2010 at 12:23 PM, Norbert Hartl <[hidden email]> wrote:
Hi Jan,

that looks great. I really would like to have a look at the code. May I have a few questions upfront:

Ok, I will upload the code this evening.
 
- I assume MAXMLTestPerson is the class name of the instance you are serializing. I would avoid exposing an implementation detail to the outside world. Do you use that information on parse time? I would expect that you know how to parse the top level object (by service context etc.). Regarding references the detail about what to parse is in MAReferenceDescription you are using for e.g. the address. If this is all right you could go with <Person> and <Address>. This would make it possible to parse the XML with a subclass of e.g. MAXMLTestPerson

Yes MAXMLTestPerson is the class name. This was the easiest way to serialize instances of classes that have the same Magritte description. This behaviour is implemented in MAXMLWriter, a subclass of MAWriter. It can be easily customized by creating your own subclass of this visitor.

 
- You inlined the address instance into the person. Is this exchangable? I'm not sure I'll go for REST but if yes then I would like to do it by reference. Let's say <adress id="http://my.service.srv/address/12345"> ...

The current implementation inlines the first occurrence of an object and adds an id attribute. If an object occurs multiple times than a reference to the id is inlined. For example:

Smalltalk:

personWithFriendsCycle

    | bill john carl |
   
    bill := MAXMLTestPerson new
        name: 'Bill';
        yourself.
    john := MAXMLTestPerson new
        name: 'John';
        yourself.
    carl := MAXMLTestPerson new
        name: 'Carl';
        friends: (OrderedCollection with: bill with: john);
        yourself.
       
    bill friends: (OrderedCollection with: john with: carl).
    john friends: (OrderedCollection with: bill with: carl).
   
    ^carl

XML:

<MAXMLTestPerson id="1">
    <name>Carl</name>
    <friends>
        <OrderedCollection>
            <MAXMLTestPerson id="2">
                <name>Bill</name>
                <friends>
                    <OrderedCollection>
                        <MAXMLTestPerson id="3">
                            <name>John</name>
                            <friends>
                                <OrderedCollection>
                                    <MAXMLTestPerson ref="2"/>
                                    <MAXMLTestPerson ref="1"/>
                                </OrderedCollection>
                            </friends>
                        </MAXMLTestPerson>
                        <MAXMLTestPerson ref="1"/>
                    </OrderedCollection>
                </friends>
            </MAXMLTestPerson>
            <MAXMLTestPerson ref="3"/>
        </OrderedCollection>
    </friends>
</MAXMLTestPerson>

 
- What do you do with the date field in birthday? Is this a fixed format or do you specify this over magritte?

This is also implemented using the MAXMLWriter visitor and can be easily customized per description class.

Jan.
 


On 09.02.2010, at 11:59, Jan van de Sandt wrote:

Hello Norbert,

I have developed some code to serialize object to XML and visa versa using their Magritte descriptions. It is not completely finished yet but for standard scenario's it works fine.

Here an example where an instance of MAXMLTestPerson is serialized to XML.

   <MAXMLTestPerson>
        <name>Bill Gates</name>
        <address>
            <MAXMLTestAddress>
                <city>Amsterdam</city>
                <street>Mainstreet</street>
            </MAXMLTestAddress>
        </address>
        <birthDate>1966-10-20</birthDate>
    </MAXMLTestPerson>

It can be de-serialized using MAXMLParser:

    MAXMLParser parse: self personWithAddressXML readStream.

The serialization process can be customized. I still have to add proper error handling. My intention was to add it to the Magritte add-ons repository when the error handling was fully working. If you want I can add it sooner so you can have a look.

Jan.




On Tue, Feb 9, 2010 at 11:22 AM, Norbert Hartl <[hidden email]> wrote:
Hi,

at the moment I'm thinking about a new project. The project will need a Web API to communicate with an iphone. To me it is quite obvious to implement the API part as a request handler. But when it comes to generation of e.g. XML I'm not sure what is the best way to do.

Sure, the seaside way to do it is to create my own canvas and every object needs to draw itself onto the canvas. But then I have magritte and a lot could be done automatically. Using xpath in the descriptions I could use Pastell to deserialize objects. To produce the output there could be a similar way. This would be some kind of XML binding then.

I wanted to ask if there is anything already available that could help me on my way or if there dedicated ideas how to solve this in seaside.

thanks  in advance,

Norbert



_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki



--
Jan van de Sandt
gsm: +31 (0)6 3039 5998

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Philippe Marschall
In reply to this post by NorbertHartl
2010/2/11 Norbert Hartl <[hidden email]>:
> Hi Philippe,
>
> that is close to what I was searching for. I was glad to see that top feeder is using the audioscrobbler code (only a few tweaks). Did I miss somehting or is this just the parsing of the format?

Right, it's just parsing.

> The code does not seem to be audioscrobbler dependent. Is there a chance to rip the XML part out of the package?

Sure, it's simply a matter of doing it. Just move the -Magritte
package and ASObject.

> Adding a writer to this code base would already lead to a descent magritte XML handling as far as I could see from a short peek.

Right you'd just have to do the inverse and create nodes.

Cheers
Philippe
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

NorbertHartl

On 11.02.2010, at 22:05, Philippe Marschall wrote:

> 2010/2/11 Norbert Hartl <[hidden email]>:
>> Hi Philippe,
>>
>> that is close to what I was searching for. I was glad to see that top feeder is using the audioscrobbler code (only a few tweaks). Did I miss somehting or is this just the parsing of the format?
>
> Right, it's just parsing.
>
>> The code does not seem to be audioscrobbler dependent. Is there a chance to rip the XML part out of the package?
>
> Sure, it's simply a matter of doing it. Just move the -Magritte
> package and ASObject.
>
I started to factor the code out into a package Magritte-XMLBinding. I divided ASObject into MXObject and ASObject containing the XML stuff and its subclass ASObject containing the network stuff (curl etc.). I moved all magritte stuff to the the Magritte-XMLBinding package. I try to reconstruct a working Audioscrobbler and Topfeeder package. Maybe you are willing to use the new package then.

I've found a reference to NAUrlDescription which I don't have. Package install didn't complain and I don't know where I can get it.
 
>> Adding a writer to this code base would already lead to a descent magritte XML handling as far as I could see from a short peek.
>
> Right you'd just have to do the inverse and create nodes.
>
Yes, this should be straight forward. This will be step 2 after the refactoring.

Norbert
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

NorbertHartl
In reply to this post by Philippe Marschall
One other thing. I use a pier-1.2 image. The Magritte contained in here seems pretty new. All of the class methods that AudioScrobbler uses seem to have vanished. Is there a compat package that gives to class side methods and calls the instance methods instead?  Otherwise I'll have a look and I could upgrade AudioScrobbler to a newer magritte.

Norbert

On 11.02.2010, at 22:05, Philippe Marschall wrote:

> 2010/2/11 Norbert Hartl <[hidden email]>:
>> Hi Philippe,
>>
>> that is close to what I was searching for. I was glad to see that top feeder is using the audioscrobbler code (only a few tweaks). Did I miss somehting or is this just the parsing of the format?
>
> Right, it's just parsing.
>
>> The code does not seem to be audioscrobbler dependent. Is there a chance to rip the XML part out of the package?
>
> Sure, it's simply a matter of doing it. Just move the -Magritte
> package and ASObject.
>
>> Adding a writer to this code base would already lead to a descent magritte XML handling as far as I could see from a short peek.
>
> Right you'd just have to do the inverse and create nodes.
>
> Cheers
> Philippe
> _______________________________________________
> Magritte, Pier and Related Tools ...
> https://www.iam.unibe.ch/mailman/listinfo/smallwiki


_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Philippe Marschall
In reply to this post by NorbertHartl
2010/2/15 Norbert Hartl <[hidden email]>:

>
> On 11.02.2010, at 22:05, Philippe Marschall wrote:
>
>> 2010/2/11 Norbert Hartl <[hidden email]>:
>>> Hi Philippe,
>>>
>>> that is close to what I was searching for. I was glad to see that top feeder is using the audioscrobbler code (only a few tweaks). Did I miss somehting or is this just the parsing of the format?
>>
>> Right, it's just parsing.
>>
>>> The code does not seem to be audioscrobbler dependent. Is there a chance to rip the XML part out of the package?
>>
>> Sure, it's simply a matter of doing it. Just move the -Magritte
>> package and ASObject.
>>
> I started to factor the code out into a package Magritte-XMLBinding. I divided ASObject into MXObject and ASObject containing the XML stuff and its subclass ASObject containing the network stuff (curl etc.). I moved all magritte stuff to the the Magritte-XMLBinding package. I try to reconstruct a working Audioscrobbler and Topfeeder package. Maybe you are willing to use the new package then.

Sure, absolutely.

> I've found a reference to NAUrlDescription which I don't have. Package install didn't complain and I don't know where I can get it.

NetworkAddress from:
http://source.lukas-renggli.ch/magritteaddons.html

Cheers
Philippe

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Web Interface and XML binding

Philippe Marschall
In reply to this post by NorbertHartl
2010/2/15 Norbert Hartl <[hidden email]>:
> One other thing. I use a pier-1.2 image. The Magritte contained in here seems pretty new. All of the class methods that AudioScrobbler uses seem to have vanished. Is there a compat package that gives to class side methods and calls the instance methods instead?  Otherwise I'll have a look and I could upgrade AudioScrobbler to a newer magritte.

Yepp, just adding a #new and a cascade. But I can do that as well.

Cheers
Philippe

_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki