The method implements:
public class SingleBand implements Performer{
public SingleBand(){}
private Collection<Instrument> instruments;
public void setInstrument(Collection<Instrument> instruments){
this.instruments = instruments;
}
public void perform() {
// TODO Auto-generated method stub
for(Instrument instrument: instruments){
instrument.play();
}
}
}
the bean settings:
<bean id="band" class="com.performence.SingleBand"> <property name="instrument"> <list> <ref bean='piano'/> <ref bean='voilin'/> <ref bean='piano'/> <ref bean='voilin'/> </list> </property> </bean> <bean id="piano" class="com.performence.Piano"/> <bean id="voilin" class="com.performence.Violin"/> </beans>
test method :
public static void main(String args[]){
BeanFactory factory = new XmlBeanFactory(new FileSystemResource("bean.xml"));
Performer per = (Performer)factory.getBean("band");
per.perform();
}
}
output:
piano playing.......
violin playing.......
piano playing.......
violin playing.......
if change the <list> to <set> in the bean.xml
output :
piano playing.......
violin playing.......