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