I am a relatively new Spring user, and i am interested to use this framework to load a complex nested configuration.
The following is a pseudo code of my architecture design:
class **A** implements runnable{
int x;
Collection<**B**> clist; //not fixed size list,
run(){
// if (something happens)
// new Thread(**B**(y,z,w))
}
}
class **B** implements runnable{
int y;
int z;
int w;
Array<**C**> bclist; // fixed size array of C known at init time
run(){
process...
}
}
class **C**{
int v;
int l;
}
i need to be able to configure A.x, B.y , B.z, B.w , B.clist, C.v and C.l
I have a single problem that is relevant to the initialization of B for every new Thread, i don’t know at compile time if clist will stay empty, and only at runtime i will know how many threads will be created. for every new thread i create new B with the same configuration.
(i looked over autowire and prototype features , and i suspect it somehow may help)
EDIT
Here i have xml example file:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="A" class="...">
<property name="x" value="150" />
<!-- HERE IS MY PROBLEM-->
<property name="clist">
<list>
<ref bean="B" />
</list>
</bean>
<bean id="B" class="...">
<property name="y" value="20" />
<property name="z" value="7" />
<property name="w" value="7" />
<property name="bclist">
<list>
<ref bean="C" />
</list>
</bean>
<bean id="C" class="...">
<property name="v" value="3" />
<property name="l" value="1" />
</bean>
</beans>
I have a possible solution to this issue, it may be not optimal.
in the A bean in the xml i may comment out the setting of the clist (no including it at all in the structure),
and when i create in java code the B bean , i may use getBean(“B”) every time , while defining the B bean in the xml as prototype.
Like this :
Java code: