alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Spring Framework example source code file (collections.xml)

This example Spring Framework source code file (collections.xml) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Spring Framework tags/keywords

commit, could, could, doctype, mapandset, mapandset, public, rod's, simple, spring//dtd, try, two, two, utf-8

The Spring Framework collections.xml source code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

	<bean id="jenny" class="org.springframework.beans.TestBean">	
		<property name="name">Jenny
		<property name="age">30
		<property name="spouse">
		<!-- Could use id and href -->
			<ref local="david"/>
		</property>
	</bean>
	
	<bean id="david" class="org.springframework.beans.TestBean">	
		<description>
			Simple bean, without any collections.
		</description>
		<property name="name">
			<description>The name of the user
			<value>David
		</property>
		<property name="age">27
	</bean>
	
	<bean id="rod" class="org.springframework.beans.TestBean">	
		<property name="name">Rod
		<property name="age">32
		<property name="friends">
			<description>List of Rod's friends
			<list>
				<ref local="jenny"/>
				<ref local="david"/>
			</list>
		</property>
	</bean>
	
	<bean id="pJenny" class="org.springframework.beans.TestBean" scope="prototype">
		<property name="name">Jenny
		<property name="age">30
		<property name="spouse">
		<!-- Could use id and href -->
			<ref local="david"/>
		</property>
	</bean>

	<bean id="pDavid" class="org.springframework.beans.TestBean" scope="prototype">
		<property name="name">David
		<property name="age">27
	</bean>

	<bean id="pRod" class="org.springframework.beans.TestBean" scope="prototype">
		<property name="name">Rod
		<property name="age">32
		<property name="friends">
			<list>
				<ref local="pJenny"/>
				<ref local="pDavid"/>
			</list>
		</property>
	</bean>

	<!--
		Try setting a collection property to a single value
	-->
	<bean id="loner" class="org.springframework.beans.TestBean">	
		<property name="name">loner
		<property name="age">26
		<property name="friends">
			<list>
				<ref local="david"/>
			</list>
		</property>
	</bean>
	
	<bean id="jumble" class="org.springframework.beans.factory.xml.MixedCollectionBean">	
		<property name="jumble">
			<list>
				<ref local="david"/>
				<value>literal
				<ref local="jenny"/>
				<idref local="rod"/>
			</list>
		</property>
	</bean>
	
	<bean id="jumble2" class="org.springframework.beans.factory.xml.MixedCollectionBean" lazy-init="true">
		<property name="jumble">
			<list>
				<ref local="david"/>
				<value>literal
				<ref local="jenny"/>
				<idref bean="rod"/>
				<idref bean="rod2"/>
			</list>
		</property>
	</bean>

	<bean id="verbose" class="org.springframework.beans.TestBean">
		<property name="name">verbose
	</bean>
	
	<bean id="verbose2" class="org.springframework.beans.TestBean">	
		<property name="name">
	</bean>

	<bean id="verbose3" class="org.springframework.beans.TestBean">	
		<property name="name">
	</bean>

	<bean id="emptyMap" class="org.springframework.beans.factory.HasMap">
		<property name="map">
			<map>
			</map>
		</property>
	</bean>
	
	<bean id="literalMap" class="org.springframework.beans.factory.HasMap">	
		<property name="map">
			<map>
				<entry key="foo" value="bar"/>
				<entry key="fi" value="fum"/>
				<entry key="fa">
			</map>
		</property>
	</bean>

	<bean id="mixedMap" class="org.springframework.beans.factory.HasMap">
		<property name="map">
			<map>
				<entry key-ref="fooKey">
					<value type="java.lang.Integer">10
				</entry>
				<entry>
 					<key>
						<ref bean="jennyKey"/>
					</key>
					<ref local="jenny"/>
				</entry>
				<entry>
 					<key>
 						<bean class="java.lang.Integer">
 							<constructor-arg value="5"/>
						</bean>
					</key>
					<idref bean="david"/>
				</entry>
			</map>
		</property>
	</bean>

	<bean id="fooKey" class="java.lang.String">
		<constructor-arg value="foo"/>
	</bean>

	<bean id="jennyKey" class="java.lang.String">
		<constructor-arg value="jenny"/>
	</bean>

	<bean id="pMixedMap" class="org.springframework.beans.factory.HasMap" scope="prototype">
		<property name="map">
			<map>
				<entry key="foo" value="bar"/>
				<entry key="jenny" value-ref="pJenny"/>
			</map>
		</property>
	</bean>

	<bean id="mixedMapWithList" class="org.springframework.beans.factory.HasMap">
		<property name="map">
			<map>
				<entry>
					<key>
					<value>bar
				</entry>
				<entry key="jenny">
				<entry key="list">
					<list>
						<value>zero
						<map>
							<entry key="fo">bar
							<entry key="jen">
						</map>
						<list>
							<ref local="jenny"/>
							<value>ba
						</list>
						<null/>
					</list>
				</entry>
				<entry key="map">
					<map>
						<entry key="foo">bar
						<entry key="jenny">
					</map>
				</entry>
			</map>
		</property>
	</bean>
	
	<bean id="emptySet" class="org.springframework.beans.factory.HasMap">
		<property name="set">
			<set>
			</set>
		</property>
	</bean>


	<bean id="set" class="org.springframework.beans.factory.HasMap">
		<property name="set">
			<set>
				<value>bar
				<ref local="jenny"/>
				<null/>
			</set>
		</property>
	</bean>

	<bean id="emptyProps" class="org.springframework.beans.factory.HasMap">
		<property name="props">
			<props>
			</props>
		</property>
	</bean>
	
	
	<bean id="props" class="org.springframework.beans.factory.HasMap">	
		<property name="props">
			<props>
				<prop key="foo">bar
				<prop key="2">TWO
			</props>
		</property>
	</bean>
	
	<bean id="propsViaMap" class="org.springframework.beans.factory.HasMap">
		<property name="props">
			<map>
				<entry key="foo" value="bar"/>
				<entry key="2" value="TWO"/>
			</map>
		</property>
	</bean>

	<bean id="objectArray" class="org.springframework.beans.factory.HasMap">
		<property name="objectArray">
			<list>
				<value>one
				<ref local="jenny"/>
			</list>
		</property>
	</bean>
	
	<bean id="classArray" class="org.springframework.beans.factory.HasMap">	
		<property name="classArray">
			<list>
				<value>java.lang.String
				<value>java.lang.Exception
			</list>
		</property>
	</bean>
	
	<bean id="integerArray" class="org.springframework.beans.factory.HasMap">
		<property name="integerArray">
			<list>
				<value>0
				<value>1
				<value>2
			</list>
		</property>
	</bean>

	<bean id="listFactory" class="org.springframework.beans.factory.config.ListFactoryBean">
		<property name="sourceList">
			<list>
				<value>bar
				<value>jenny
			</list>
		</property>
		<property name="targetListClass">
			<value>java.util.LinkedList
		</property>
	</bean>

	<bean id="pListFactory" class="org.springframework.beans.factory.config.ListFactoryBean">
		<property name="sourceList">
			<list>
				<value>bar
				<value>jenny
			</list>
		</property>
		<property name="targetListClass">
			<value>java.util.LinkedList
		</property>
		<property name="singleton">
			<value>true
		</property>
	</bean>

	<bean id="setFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
		<property name="sourceSet">
			<set>
				<value>bar
				<value>jenny
			</set>
		</property>
		<property name="targetSetClass">
			<value>java.util.TreeSet
		</property>
	</bean>

	<bean id="pSetFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
		<property name="sourceSet">
			<set>
				<value>bar
				<value>jenny
			</set>
		</property>
		<property name="targetSetClass">
			<value>java.util.TreeSet
		</property>
		<property name="singleton">
			<value>true
		</property>
	</bean>

	<bean id="mapFactory" class="org.springframework.beans.factory.config.MapFactoryBean">
		<property name="sourceMap">
			<map>
				<entry key="foo">bar
				<entry key="jen">jenny
			</map>
		</property>
		<property name="targetMapClass">
			<value>java.util.TreeMap
		</property>
	</bean>

	<bean id="pMapFactory" class="org.springframework.beans.factory.config.MapFactoryBean">
		<property name="sourceMap">
			<map>
				<entry key="foo">bar
				<entry key="jen">jenny
			</map>
		</property>
		<property name="targetMapClass">
			<value>java.util.TreeMap
		</property>
		<property name="singleton">
			<value>true
		</property>
	</bean>

	<bean id="setAndMap" class="org.springframework.beans.factory.xml.XmlBeanCollectionTests$MapAndSet">
		<constructor-arg>
			<map>
				<entry key="key1" value="val1"/>
				<entry key="key2" value="val2"/>
				<entry key="key3" value="val3"/>
			</map>
		</constructor-arg>
	</bean>

	<bean id="enumSetFactory" class="org.springframework.beans.factory.config.SetFactoryBean">
		<property name="sourceSet">
			<set>
				<value type="org.hibernate.FlushMode">NEVER
				<value type="org.hibernate.FlushMode">COMMIT
			</set>
		</property>
	</bean>

</beans>

Other Spring Framework examples (source code examples)

Here is a short list of links related to this Spring Framework collections.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.