Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have some Abstract Factory

public interface AbstractViewersFactory {
    IAbstractShapeViewer createRectangle(BaseOperationsListener<RectangleDTO> p);
    IAbstractShapeViewer createOval(BaseOperationsListener<OvalDTO> p);
    IAbstractShapeViewer createTriangle(BaseOperationsListener<TriangleDTO> p);
}

And Its implementation Draw2DViewersFactory. Now, I want create some class that will take responsibility for creating presenters/viewers by model and configurate it by Spring. So, I need describe in .xml configuration what method it should call. It can be something like this (pseudo config)

<bean creator>
<constructor-args>
<list>
    <bean describe-item> <constructor-args>model=Rectangle.class, method-for-viewer-create="createRectangle"</args>
    <bean describe-item> <constructor-args>model=Oval.class, method-for-viewer-create="createOval"</args>
<list>
</constructor-args>
</bean>

How I can do it?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
259 views
Welcome To Ask or Share your Answers For Others

1 Answer

Even though your question is very unclear, I think I got what you wanted to know. You can define a spring bean as a factory instance and then set the factory method of this bean like this:

<bean id="myFactoryBean"
  class="AbstractViewersFactory">

  <bean id="exampleBean"
  factory-bean="myFactoryBean"
  factory-method="createRectangle"/>

Hope this helps. Google this for further information :p

greetings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...