facebook

Any way to autogenerate inline code to copy bean properties?

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #265084 Reply

    joquarky
    Member

    I’ve been searching around for an Eclipse plugin or utility that will automatically generate inline code to rougly duplicate the behavior of org.apache.commons.beanutils.BeanUtils.copyProperties().

    This seems like something that would be useful for a few scenarios where copyProperties() may not be the best tool for the job; for example if you want to:

    – copy all properties except one or a few
    – ensure that a compiler error arises if someone changes an important property name in a view object
    – have more direct control over how properties are copied
    – increase performance by avoiding the reflection/introspection overhead of copyProperties()

    In my case, it’s mostly a combination of the first two, as I’m finding it quite tedious to manually type (sometimes) dozens of “object1.setThing(object2.getThing());” statements in many of several dozen EJBs.

    In this case, object1 is a model object, and object2 is a VO. In some methods, I want only some properties to be writeable, and in other methods I want all properties to be writable. In the latter case, I can just use the BeanUtils.copyProperties(), but in the former I find that inserting dozens of lines of set(get()) statements to be unnecessarily tedious.

    I’m still fairly new to this stuff so perhaps I’m overlooking a pattern which people are already using for this kind of situation?

    Any suggestions would be greatly appreciated! 😀

    Thanks,

    Josef

    #265092 Reply

    Riyad Kalla
    Member

    Josef,
    Why not write a wrapper to BeanUtils that does what you want as it seems the core copying functionality is already there for you.

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Any way to autogenerate inline code to copy bean properties?

You must be logged in to post in the forum log in