package com.nedap.archie.rm.archetypes;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nedap.archie.query.APathQuery;
import com.nedap.archie.rm.RMObject;
import com.nedap.archie.rminfo.ArchieRMInfoLookup;

import javax.xml.bind.annotation.XmlTransient;

/**
 * Created by pieter.bos on 04/11/15.
 */
public class Pathable extends RMObject {
    //TODO: implement according to spec: pathExists(path), pathUnique(path), pathOfItem(pathable)

    @JsonIgnore
    @XmlTransient
    private Pathable parent;

    public Object itemAtPath(String s) {
        return new APathQuery(s).find(ArchieRMInfoLookup.getInstance(), this);
    }

    @JsonIgnore
    @XmlTransient
    public Pathable getParent() {
        return parent;
    }

    public void setParent(Pathable parent) {
        this.parent = parent;
    }

    /**
    * Utility method to set this object as the parent of the given child,
    * if the child is not null
    */
    protected void setThisAsParent(Pathable child) {
        if(child != null) {
            child.setParent(this);
        }
    }

}

@@ -263,16 +263,39 @@
 ansient;
+%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -659,24 +659,166 @@
 this);%0A    %7D
+%0A    %0A    public List%3CObject%3E itemsAtPath(String s) %7B%0A        return new APathQuery(s).findList(ArchieRMInfoLookup.getInstance(), this);%0A    %7D
 %0A%0A    @JsonI

add the itemsAtPath-method, which uses the new findList method of APathQuery