xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="player" class="dice.Player">
<!-- <bean id="collection" class="dice.Player_List">
<property name="value">
<list>
<value>이자바</value>
<value>김정보</value>
<value>박기술</value>
</list>
</property></bean>
</beans> -->
<!-- <bean id="collection" class="dice.Player_Set">
<property name="address">
<set value-type="java.lang.String">
<value>서울시</value>
<value>인천시</value>
<value>대구시</value>
</set>
</property></bean>
</beans> -->
<!-- <bean id="collection" class="dice.Player_Map">
<property name="phone">
<map>
<entry key="이자바" value="010-9510-6272"></entry>
<entry key="김길동" value="010-9501-1111"></entry>
<entry key="핸드폰" value="010-9888-1111"></entry>
</map>
</property></bean>
</beans> -->
<bean id="collection" class="dice.Player_Properties">
<property name="member">
<props>
<prop key="java">이자바</prop>
<prop key="jsp">홍길동</prop>
<prop key="db">디비</prop>
<prop key="javascript">스크립트</prop>
</props>
</property></bean>
</beans>
package dice;
import java.util.Map;
import java.util.Properties;
public class Player_Properties {
Properties member;
Dice d;
Player_Properties(){}
Player_Properties(Properties member){
this.member = member;
}
public Properties getMember() {
return member;
}
public void setMember(Properties member) {
this.member = member;
}
public void SetDice(Dice d){
this.d = d;
}
// 1. 생성자 매개변수
// 2. Setter 매개변수
public void play(){
int value = d.getDiceValue();
System.out.println(value);
}
}
package dice;
import java.util.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class CollectionMain {
public static void main(String[] args) {
ApplicationContext factory = new ClassPathXmlApplicationContext("/dice/dice.xml");
/* Player_List p = (Player_List)factory.getBean("collection");
List list = p.getValue();
for(int i=0;i<list.size();i++){
System.out.println(list.get(i));
}*/
/* Player_Set p = (Player_Set)factory.getBean("collection");
Set<String> add = p.getAddress();
Iterator it = add.iterator();
while(it.hasNext()==true){
System.out.println(it.next());
}*/
/* Player_Map p = (Player_Map)factory.getBean("collection");
Map<String, String> phone = p.getphone();
Set keys = phone.keySet();
Iterator it = keys.iterator();
while(it.hasNext()==true){
String key = (String)it.next();
System.out.println(keys+ ":" +phone.get(key));
} */
Player_Properties p = (Player_Properties)factory.getBean("collection");
Properties props = p.getMember();
Enumeration e = props.keys(); // JAVA. key값
Enumeration e2 = props.elements(); // 이자바, valuy값
while(e.hasMoreElements()==true){
String key = (String)e.nextElement();
String value = (String)e2.nextElement();
System.out.println(key+ ":" +value);
}
}
}