RE: Copying DataObjects

From: Cris Daniluk (cris.danilu..laraview.com)
Date: Wed Mar 23 2005 - 22:18:55 EST

  • Next message: Damir Bijuklic: "RE: Firebird generators"

    >
    > > We frequently have a need to copy the properties of
    > DataObjects back
    > > and forth (either to other DataObjects, or to beans further
    > down the
    > > chain). BeanUtils is an obvious choice, but unfortunately it takes
    > > properties from CayenneDomainObject as well (specifically, the
    > > persistence state).
    >
    > For encoding the DataObject properties for the XML encoding
    > work I've been doing, I have something like the following:
    >
    > public void encodeAsXML(XMLEncoder encoder) {
    >
    > EntityResolver er = getDataContext().getEntityResolver();
    > ObjEntity object = er.lookupObjEntity(getClass());
    >
    > for (Iterator it = object.getDeclaredAttributes().iterator();
    > it.hasNext();) {
    > ObjAttribute att = (ObjAttribute) it.next();
    > String name = att.getName();
    > encoder.encodeProperty(name, readNestedProperty(name));
    > }
    > }
    >
    > This is in CayenneDataObject, and it only retrieves declared
    > attributes. I had to do this for the exact same reason
    > (encoding persistent state info in XML doesn't make much
    > sense). Anyway, this may be another way to satisfy your needs.
    >

    I initially was doing that, but wanted something that was a little more
    reusable, to go DataObject <-> Data Object, DataObject -> Bean, and Bean ->
    DataObject. Of course, for the rest of the world who isn't using 1.5, it
    doesn't do much good :)

    Cris



    This archive was generated by hypermail 2.0.0 : Wed Mar 23 2005 - 22:18:52 EST