Announcement Announcement Module
Collapse
No announcement yet.
method lookup Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • method lookup

    currently I'm doing some XML bindung stuff with jakarta commons digester. If you haven't heard of it maybe you know XStream. The point is "digesting" my XML bindings consumes a lot of small prototype objects (e.g. author, adress...).

    I wanted to get these prototype objects via spring but I couldn't because my digester instance has no relation to the framework after it gets constructed. After a while I found the topic "lookup-method injection" describing exactly my problem.


    Proposed solutions:

    Solution1: Make your class aware of Spring
    Solution2: bytcode wizardry behinde the scenes + lookup hooks in your code




    Why can't I simply use prototype objects that know how to reproduce protoypes of them self?
    "principle of least astonishment"?

    Code:
    class Author {
      public Author() {}
    
      public Author newAuthor() {
        return new Author();
      }
      ....
    }
    I inject Author prototype into xml digester. Every time the digester calls aAuthor.newAuthor() it acquires a new fresh prototyped author object. I`m not sure about this approach. Of couse, it doesn`t scale to heavyweight objectgraphs but in such case you shouldn't use prototyping anyway! right?

    Mo

  • #2
    Re: method lookup

    Originally posted by moo
    Why can't I simply use prototype objects that know how to reproduce protoypes of them self?
    "principle of least astonishment"?

    Code:
    class Author {
      public Author() {}
    
      public Author newAuthor() {
        return new Author();
      }
      ....
    }
    Is the digester a class you wrote yourself?
    In that case: why don't you just configure the "prototype" instances for your digester with spring and use clone() for retrieving new instances from within your digester? (If you do not want to implement Cloneable, you can alternatively use serialization for creating copies)

    BTW: I would find it astonishing to have an instance (non-static) method for creating a new instance.

    Regards,
    Andreas

    Comment

    Working...
    X