Magritte / XML bridge

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

Magritte / XML bridge

Stéphane Ducasse
Hi guys

I would like to show in the magritte chapter I'm revisiting a bit more meat.
I'm playing with magritte 30 and I would like to know if there is a way to save objects based on their magritte description.

Stef
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: Magritte / XML bridge

NorbertHartl

Am 28.06.2012 um 21:15 schrieb Stéphane Ducasse:

> Hi guys
>
> I would like to show in the magritte chapter I'm revisiting a bit more meat.
> I'm playing with magritte 30 and I would like to know if there is a way to save objects based on their magritte description.
>
Yes, there is. There is a description in an old blog post of mine [1]. Don't be misled that magritte2 is mentioned there. It works as well with magritte3 (thanks to Nick Ager). You can get it

Gofer new
        renggli: 'magritte3addons';
        package: 'ConfigurationOfMagritte3AddOns';
        load

and load the default.

In a nutshell:

You add to your descriptions "beXmlAttribute" or "beXmlElement". Then you can store an object with

myObject magritteDescription toXml: myObject

hope that helps,

Norbert
         

[1] http://norbert.hartl.name/blog/magritte-xmlbinding/




_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-project] Magritte / XML bridge

Stéphane Ducasse

On Jun 29, 2012, at 10:54 AM, Norbert Hartl wrote:

>
> Am 28.06.2012 um 21:15 schrieb Stéphane Ducasse:
>
>> Hi guys
>>
>> I would like to show in the magritte chapter I'm revisiting a bit more meat.
>> I'm playing with magritte 30 and I would like to know if there is a way to save objects based on their magritte description.
>>
> Yes, there is. There is a description in an old blog post of mine [1]. Don't be misled that magritte2 is mentioned there. It works as well with magritte3 (thanks to Nick Ager). You can get it
>
> Gofer new
> renggli: 'magritte3addons';
> package: 'ConfigurationOfMagritte3AddOns';
> load
>
> and load the default.

Excellent I will read it.
I'm reading magicMagritte right now.

BTW the Twitters stuff of nick is gorgeous :)

>
> In a nutshell:
>
> You add to your descriptions "beXmlAttribute" or "beXmlElement". Then you can store an object with
>
> myObject magritteDescription toXml: myObject

Ok cool.
I did that by hand in the past

importElement: aXMLItem

        | anElement |
        anElement := (self class mappingTable at: aXMLItem name) new.
        self updateBackLinkOf: anElement.
        anElement magritteDescription do:
                [ :each |
                | auth |
                auth := aXMLItem attributeAt: each accessor readSelector asString.
                (#(nil 'nil' ) includes: auth) ifFalse:
                        [ auth := each fromString: auth.
                        each accessor
                                write: auth
                                to: anElement ]].
        self base add: anElement.
        ^ anElement

>
> hope that helps,

Do you know how relationships are handled :)
>
> Norbert
>  
>
> [1] http://norbert.hartl.name/blog/magritte-xmlbinding/
>
>
>
>


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-project] Magritte / XML bridge

Stéphane Ducasse
In reply to this post by NorbertHartl
Norbert

when I load magicMagritte
and I tried the example I got an error because I got an object instead of text


visitMultipleOptionDescription: aDescription
        | options text |

        options := self object readUsing: aDescription.
        options notNil ifTrue: [
                options do: [ :each | self writeText: each asString description: aDescription ] ]
                                                                        ^^^^^^^^^^^^
I added that but this is probably wrong. I will take some time to look deeper into.

Stef


On Jun 29, 2012, at 10:54 AM, Norbert Hartl wrote:

>
> Am 28.06.2012 um 21:15 schrieb Stéphane Ducasse:
>
>> Hi guys
>>
>> I would like to show in the magritte chapter I'm revisiting a bit more meat.
>> I'm playing with magritte 30 and I would like to know if there is a way to save objects based on their magritte description.
>>
> Yes, there is. There is a description in an old blog post of mine [1]. Don't be misled that magritte2 is mentioned there. It works as well with magritte3 (thanks to Nick Ager). You can get it
>
> Gofer new
> renggli: 'magritte3addons';
> package: 'ConfigurationOfMagritte3AddOns';
> load
>
> and load the default.
>
> In a nutshell:
>
> You add to your descriptions "beXmlAttribute" or "beXmlElement". Then you can store an object with
>
> myObject magritteDescription toXml: myObject
>
> hope that helps,
>
> Norbert
>  
>
> [1] http://norbert.hartl.name/blog/magritte-xmlbinding/
>
>
>
>


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-project] Magritte / XML bridge

NorbertHartl
In reply to this post by Stéphane Ducasse

Am 29.06.2012 um 15:17 schrieb Stéphane Ducasse:

>
> On Jun 29, 2012, at 10:54 AM, Norbert Hartl wrote:
>
>>
>> Am 28.06.2012 um 21:15 schrieb Stéphane Ducasse:
>>
>>> Hi guys
>>>
>>> I would like to show in the magritte chapter I'm revisiting a bit more meat.
>>> I'm playing with magritte 30 and I would like to know if there is a way to save objects based on their magritte description.
>>>
>> Yes, there is. There is a description in an old blog post of mine [1]. Don't be misled that magritte2 is mentioned there. It works as well with magritte3 (thanks to Nick Ager). You can get it
>>
>> Gofer new
>> renggli: 'magritte3addons';
>> package: 'ConfigurationOfMagritte3AddOns';
>> load
>>
>> and load the default.
>
> Excellent I will read it.
> I'm reading magicMagritte right now.
>
> BTW the Twitters stuff of nick is gorgeous :)
>
>>
>> In a nutshell:
>>
>> You add to your descriptions "beXmlAttribute" or "beXmlElement". Then you can store an object with
>>
>> myObject magritteDescription toXml: myObject
>
> Ok cool.
> I did that by hand in the past
>
> importElement: aXMLItem
>
> | anElement |
> anElement := (self class mappingTable at: aXMLItem name) new.
> self updateBackLinkOf: anElement.
> anElement magritteDescription do:
> [ :each |
> | auth |
> auth := aXMLItem attributeAt: each accessor readSelector asString.
> (#(nil 'nil' ) includes: auth) ifFalse:
> [ auth := each fromString: auth.
> each accessor
> write: auth
> to: anElement ]].
> self base add: anElement.
> ^ anElement
>
Well, it started as an excersize to avoid having to do things like that
>>
>> hope that helps,
>
> Do you know how relationships are handled :)

Relationships are one of the weaker points in magritte. It would need some love to make it more usable. In Magritte-XML we took a few side ways.
When it comes to descriptions in relationships it is important who is in control of the "real" description of an object. In Magritte-Xml we support two use cases. The default option is to support inheritance. That means if you navigate a relationship each object is asked for its description. This way an object you get can be a subclass of the object you described. The second option I need more often is to inject descriptions into a relationship. Meaning the description of the relationship defines the description for the contained objects. This way I can alter the use of my objects by the way the objects are approached/by use case. This can be done by setting #reference: on your relationship description and by specifying "beDescribedByReference" to the relationship description. Sadly I couldn't come up with a nicer selector :)
As an example I use

COUserSession>>#userDescription
        <magritteDescription>
        ^MAToOneRelationDescription new
                accessor: #user;
                label: 'User of App';
                classes: (Array with: COUser);
                beDescribedByReference;
                reference: (COUser new remoteDescription kind: COUser);  
                beXmlElement;
                beInlined;
                priority: 20;
                yourself

Here "remoteDescription" includes a reduced view of the user for remote usage. It contains just two values of the user instead of everything. By additionally defining "beInlined" you can prevent the relationship to create an additional element. Otherwise the relationship would create a xml element and the object as well.
While I'm writing this I'm not sure if the setting for kind: is still needed. Nick did something so you don't need to set it like this, I think. I hope he will read this and clarifies the use.

Regarding your other mail. I cannot tell much about the option descriptions in Magritte-Xml. I never used them myself and so I'm no expert. Jan could say something about them and IIRC Nick (again) did something with the multiple option description.

hope that helps,

Norbert
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Pharo-project] Magritte / XML bridge

Stéphane Ducasse
>>
>>
> Well, it started as an excersize to avoid having to do things like that

:)

>>> hope that helps,
>>
>> Do you know how relationships are handled :)
>
> Relationships are one of the weaker points in magritte.

Yes.
I think that we should increase the use of magritte so that it can improve.

> It would need some love to make it more usable. In Magritte-XML we took a few side ways.
> When it comes to descriptions in relationships it is important who is in control of the "real" description of an object. In Magritte-Xml we support two use cases. The default option is to support inheritance. That means if you navigate a relationship each object is asked for its description. This way an object you get can be a subclass of the object you described. The second option I need more often is to inject descriptions into a relationship. Meaning the description of the relationship defines the description for the contained objects. This way I can alter the use of my objects by the way the objects are approached/by use case. This can be done by setting #reference: on your relationship description and by specifying "beDescribedByReference" to the relationship description. Sadly I couldn't come up with a nicer selector :)
> As an example I use
>
> COUserSession>>#userDescription
> <magritteDescription>
> ^MAToOneRelationDescription new
> accessor: #user;
> label: 'User of App';
> classes: (Array with: COUser);
> beDescribedByReference;
> reference: (COUser new remoteDescription kind: COUser);  
> beXmlElement;
> beInlined;
> priority: 20;
> yourself
>
> Here "remoteDescription" includes a reduced view of the user for remote usage. It contains just two values of the user instead of everything. By additionally defining "beInlined" you can prevent the relationship to create an additional element. Otherwise the relationship would create a xml element and the object as well.
> While I'm writing this I'm not sure if the setting for kind: is still needed. Nick did something so you don't need to set it like this, I think. I hope he will read this and clarifies the use.

Somehow. I have to play with it. And if you come at esug I would really like to sit with you.

One of my simple use case is that I have a container and elements and I would like to save in xml the container and its elements. Now the relation between container and elements is a relationship.

>
> Regarding your other mail. I cannot tell much about the option descriptions in Magritte-Xml. I never used them myself and so I'm no expert. Jan could say something about them and IIRC Nick (again) did something with the multiple option description.

I will look deeper into it now
>
> hope that helps,
>
> Norbert


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev