Bean Injection Collection: Set : XML Bean Property « Spring « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Spring » XML Bean PropertyScreenshots 
Bean Injection Collection: Set

       
File: context.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="collectionsDemo" class="CollectionsDemo">
        <property name="map">
            <map>
                <entry key="someValue">
                    <value>Hello World!</value>
                </entry>
                <entry key="someBean">
                    <ref local="oracle"/>
                </entry>
            </map>
        </property>
        <property name="props">
            <props>
                <prop key="firstName">
                    Jan
                </prop>
                <prop key="secondName">
                    Machacek
                </prop>
            </props>
        </property>
        <property name="set">
            <set>
                <value>Hello World!</value>
                <ref local="oracle"/>
            </set>
        </property>
        <property name="list">
            <list>
                <value>Hello World!</value>
                <ref local="oracle"/>
            </list>
        </property>
    </bean>

    <bean id="oracle" class="BookwormOracle"/>

</beans>


File: Main.java

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

public class Main {

  public static void main(String[] args) {
    BeanFactory factory = new XmlBeanFactory(new ClassPathResource("context.xml"));
    CollectionsDemo instance = (CollectionsDemofactory.getBean("collectionsDemo");
    instance.displayInfo();
  }
}

interface Encyclopedia {
  Long findLong(String entry);
}

interface Oracle {
  String defineMeaningOfLife();
}

class BookwormOracle implements Oracle {
  private Encyclopedia encyclopedia;

  public String defineMeaningOfLife() {
    Long ageOfUniverse = this.encyclopedia.findLong("AgeOfUniverse");
    Long constantOfLife = this.encyclopedia.findLong("ConstantOfLife");
    return String.valueOf(ageOfUniverse / constantOfLife);
  }

  public void setEncyclopedia(Encyclopedia encyclopedia) {
    this.encyclopedia = encyclopedia;
  }
}

class CollectionsDemo {
  private Map map;

  private Properties props;

  private Set set;

  private List list;

  public void setList(List list) {
    this.list = list;
  }

  public void setSet(Set set) {
    this.set = set;
  }

  public void setMap(Map map) {
    this.map = map;
  }

  public void setProps(Properties props) {
    this.props = props;
  }

  public void displayInfo() {

    // display the Map
    Iterator i = map.keySet().iterator();

    System.out.println("Map contents:\n");
    while (i.hasNext()) {
      Object key = i.next();
      System.out.println("Key: " + key + " - Value: " + map.get(key));
    }

    // display the properties
    i = props.keySet().iterator();
    System.out.println("\nProperties contents:\n");
    while (i.hasNext()) {
      String key = i.next().toString();
      System.out.println("Key: " + key + " - Value: " + props.getProperty(key));
    }

    // display the set
    i = set.iterator();
    System.out.println("\nSet contents:\n");
    while (i.hasNext()) {
      System.out.println("Value: " + i.next());
    }

    // display the list
    i = list.iterator();
    System.out.println("\nList contents:\n");
    while (i.hasNext()) {
      System.out.println("Value: " + i.next());
    }
  }

}




           
       
Spring-BeanInjectionCollectionSet.zip( 2,601 k)
Related examples in the same category
1. Property Setting: URL
2. PropertySetting: String Array
3. Property Setting: Stream From URL
4. Property Setting: Properties
5. Property Setting: Integer
6. Property Setting: File
7. Property Setting: Class type
8. Property Setting: Byte Array
9. Property Setting: Boolean
10. Property Setting: BigDecimal
11. Properties Setting: Date
12. Load property File In Context
13. lazy init
14. Fill Value To List
15. Fill Map
16. Fill Set
17. Fill Properties
18. Fill List To Another List
19. Fill Calendar Object To List
20. Create List Map In Context
21. Bean Injection: Map
22. Bean Injection: Collection Properties
23. Bean Injection Collection: Map
24. Bean Injection Collection: List
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.