Code Generation (Was: Re: JDOM 1.0)

From: Kevin Menard (nirvdru..egativetwenty.net)
Date: Sun Dec 12 2004 - 21:22:30 EST

  • Next message: Andrus Adamchik: "SQLActions"

    On 12/12/04 7:21 PM, "Andrus Adamchik" <andru..bjectstyle.org> wrote:

    > Thanks, I just did the switch. Actually .classpath had to be updated,
    > as all jars in "otherlib" are tagged with version numbers, so
    > jdom-b9.jar was replaced with jdom-1.0.jar.

    Bah, my bad. I must have changed it locally, and didn't append the version
    number. Sorry for that.

    Now, I have a question about the code generation stuff. I've been playing
    with the superclass template, and it'll set up an encodeAsXML() that works
    pretty. The problem is that I need to know the package of the subclass
    created, and before I go modifying
    org.objectstyle.cayenne.gen.ClassGenerator, I figured I'd ask if it was
    already available somehow.

    It's perhaps easiest to show with an example as to why. This is an
    auto-generated encodeAsXML() for my base Bookmark class:

    public void encodeAsXML(XMLEncoder encoder) {

    encoder.setRoot("Bookmark",
    "net.negativetwenty.bookmarker.models.auto._Bookmark");
            

    encoder.encodeProperty("clickCount", getClickCount());

    encoder.encodeProperty("created", getCreated());

    encoder.encodeProperty("description", getDescription());

    encoder.encodeProperty("title", getTitle());

    encoder.encodeProperty("url", getUrl());

    }

    In particular, in setRoot(), I'm feeding in a class name for the XML
    encoding, which is needed for decoding. Generally speaking though, people
    work with their subclass. As such, two problems are at hand. I'd like to
    auto-create the decode code (which is being done in a constructor that takes
    a single arg of type XMLDecoder), but then the subclass needs to provide a
    new constructor that just calls super(), which seems like a waste. But
    putting the auto-generated code in the subclass is a no go too.

    What I've done in the interim is force the user to write the decode code,
    but here again, this constructor is only defined in the subclass, so when
    decoding the XML snippet generated by the above encodeAsXML(), I'm running
    into reflection errors, since there's a name mismatch.

    So, how should I proceed? Actually, in typing this, I'm inclined to
    thinking that having the auto-generated code in the superclass won't really
    be a big deal, since the decoder is going to make it mostly transparent
    anyway (as it'll just return an Object, which incidentally will be of the
    superclass type) . . .

    -- 
    Thanks,
    Kevin
    



    This archive was generated by hypermail 2.0.0 : Sun Dec 12 2004 - 21:23:07 EST