[TransWarp] more mdl_XXX methods ?

Ulrich Eck ueck at net-labs.de
Wed Apr 2 09:41:07 EST 2003

> >
> >mdl_fromXML (fromXML) -> Convert XML to state
> Uh, that one's not gonna happen.  There are too many possible XML 
> representations of something.  Instead, I'd suggest using the 
> 'peak.storage.xmi' package to handle serialization to/from XML.

> >mdl_toXML (toXML) -> Convert state to XML
> Not gonna happen.

you're right .. this is too generic to make any sense ..

the storage.xmi package is only cabable to handle the 
XMI format right ??

so if i need to build custom xml-"DM"s i can take xmi.py as template
and write from scratch (did this for my wxPython XRC parser,
that converts XRC-Resource files into a nice component model - but
it needs some refactoring .. it was build before the peak.model changed)

> >one cannot add these methods easily because the setup
> >is done via metaclasses - that would mean, i need to
> >extend supertypes but cannot reuse the standard
> >model.Attribute/Collection/... classes but need to
> >define them by myself
> There's always monkeypatching.  :)  But really, if you wanted to add 
> something to say, an Attribute, it's not that difficult:
> class MyAttrib(model.Attribute):
>      toFields = binding.classAttr(binding.bindTo('typeObject/mdl_toFields'))
> MyAttrib and its subclasses will then have a per-class 'toFields()' method 
> based on their respective referenced types.
> You can also do it like this:
> class MyFeatureBase(model.StructuralFeature):
>      toFields = binding.classAttr(binding.bindTo('typeObject/mdl_toFields'))
> And then derive your own Attribute, Collection, etc. features again.  If 
> you look at peak.model.features, you'll see that most of the other classes 
> are maybe only 3 lines of code, as simple subclasses of 
> StructuralFeature.  This was intentional, to allow for this sort of thing.
> Keep in mind, though, that PEAK reserves the 'mdl_' prefix for its own use, 
> so if you go around adding 'mdl_' methods, they might get stomped by a 
> PEAK-specific thing later on.  Feel free to create your own prefix for any 
> special methods like this that you need.

the trick with binding.classAttr help building things like this and
helps for now .. 

thanks :)


Ulrich Eck
net-labs Systemhaus GmbH
Ebersberger Str. 46
85570 Markt Schwaben - Germany

eMail: ueck <at> net-labs.de
phone: +49 8121 4747 10
fax:   +49 8121 4747 77

More information about the PEAK mailing list