Re: writing collection of refobjects through xmiwriter

Brian Smith <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.mdr.devel
Organization CollabNet Hosting
Message-ID <[email protected]>
Hi Martin and Ronald,

Martin Matula wrote:
 > Hi Ronald,
 > Now the problem is, how to enforce that
 > XMIReferenceProvider returns href (not xmi.id) in case when XMIWriter
 > is asking for href of object not contained in the collection that was
 > sent as a parameter. If the XMIReferenceProvider would return xmi.id
 > instead of href, XMIWriter would serialize that object (although it
 > was neither in the original collection nor it is a component of any
 > object in the original collection) and all the comonents of that
 > object transitively,
 > etc.
 > Do you think that this behavior is OK or would it be better to throw
 > an exception from the XMIWriter if xmi.id is returned where href was
 > expected?
 > Martin

Currently you are proposing that XMIReferenceProvider choose which
reference to give the XMIWriter. I propose that XMIReferenceProvider
should be able to give both form of references, and that the XMIWriter
will ask for whichever one it prefers:

      public interface XMIReference {
              /*  If a.getDocumentURI().equals(b.getDocumentURI()) then
               *  "a" and "b" are in the same file and so it _may_
               * choose Otherwise, it will _always_ choose getHref().
               */
          public String getDocumentURI();
              /*  always returns href form; never returns null. The
               *  location is relative to the document URI.
               *  XMIWriter would create the link using:
               */ xmiref.getDocumentURI() + xmiref.getLocation();
          public String getLocation();
              /*  always returns xmi.id form; never returns null. The
               *  XmiWriter can use (a) while writing links to the
               *  object, and possible (b) while generating the
               *  xmi.id attribute while writing the object itself???
               */
          public String getXmiId();
      }

Sample untested implementation:
      class SimpleXMIReference implements XMIReference {
           SimpleXMIReference(String document, String xmiId) {
                 this.document = document;
                 this.xmiId = xmiId;
           }
           public String getDocumentURI() { return document; }
           public String getXmiId()       { return xmiId;    }
           public String getLocation()    { return "#" + xmiId; }
           private String document, xmiId;
      }

In this case, XMIWriter.write(Collection, XMIReferenceProvidier) should
have enough information to do what was asked, because XMIWritier would
look something like this:

   writeLink(RefObject source, RefObject dest, XMIReferenceProvider p) {
      XMIReference destRef = p.getXMIReference(dest);
      if (p.getXMIReference(source).getDocumentURI()
                                   .equals(destRef.getDocumentURI())) {
          writeXmiIdRef(dest, destRef.getXmiId());
      } else {
        writeHref(dest, destRef.getDocumentURI(), destRef.getLocation());
      }
   }

- Brian
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.