Hi,

In past years I've spend quite some time converting MMBase node graphs to strongly typed object graphs. One of the reasons for doing this is to define 'meta' models on top of the cloud. 'What is a newsitem?' (i.e. which rules need to be applied to get all the needed data from MMBase).

Due to recent developments within the VPRO I decided to have another go at it. And I came up with a working prototype of something which I think might be useful to others; or where others might be able to provide valuable feedback!

The small framework I created is annotation based; i.e. you specify the bindings to MMBase using annotations:

// --------- NewsItem.java

@Entity(builder = "news", root = true)
public class NewsItem {

        private Long number;
        private String title;
        private String subtitle;
        private String credits;

        @Field(nodeField = "intro")
        private String description;

        private String body;

@Embedded(builder = "mmevents", field = "start", convertor = EpochDateConvertor.class)
        private Date created;

@PosRel(orderDirection = Direction.DESC, queryDirection = QueryDirection.BOTH)
        private List<Image> image;

@Rel(orderDirection = Direction.DESC, orderField = "value", queryDirection = QueryDirection.DESTINATION)
        private List<Tag> tag;

// --------- Image.java

@Entity(builder = "images")
public class Image {
        private Long number;
        private String title;

// --------- Tag.java
                
@Entity(builder = "tags")
public class Tag {
        private Long number;
        private String value;


The implementation is still in concept phase, but as you can see it is already possible to define mappings for associations (works for type collections only), fields (populated by default, @Field annotation use to override properties) and associations which are treated as embedded objects. Note: at the moment I'm only considering read operations.

Entity definitions are automatically retrieved at startup of a simple MMBase module, after which binding can be done as follows:

        // retrieve node from mmbase
        Node node = cloud.getNode(nodeNumber);
                                
        // find the root entity in the registry
Object newEntityInstance = entityRegistry.get(builderName).newInstance();
                                
        // transform the node to the specified entity
        Populator.unmarshallNode(newEntityInstance, node);
                                

There is still a lot of ground to cover, but the basics work, and the populator class is still less then 200 lines of code! No public sourcecode yet, but I'd be more than happy to contribute it in the near future if others are interested.

looking forwards to ideas, criticism etc.

Peter






_______________________________________________
Developers mailing list
Developers@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/developers

Reply via email to