<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
	  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
	  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

	<bean id="userManager" class="tudu.service.impl.UserManagerImpl">
		<property name="userDAO">
			<ref bean="userDAO" />
		</property>
		<property name="roleDAO">
			<ref bean="roleDAO" />
		</property>
		<property name="todoListDAO">
			<ref bean="todoListDAO" />
		</property>
		<property name="todoDAO">
			<ref bean="todoDAO" />
		</property>
		<property name="propertyDAO">
			<ref bean="propertyDAO" />
		</property>
	</bean>

	<bean id="todoListsManager"
		class="tudu.service.impl.TodoListsManagerImpl">
		<property name="todoListDAO">
			<ref bean="todoListDAO" />
		</property>
		<property name="todoDAO">
			<ref bean="todoDAO" />
		</property>
		<property name="userManager">
			<ref bean="userManager" />
		</property>
	</bean>

	<bean id="todosManager"
		class="tudu.service.impl.TodosManagerImpl">
		<property name="todoDAO">
			<ref bean="todoDAO" />
		</property>
		<property name="todoListsManager">
			<ref bean="todoListsManager" />
		</property>
		<property name="userManager">
			<ref bean="userManager" />
		</property>
	</bean>

	<bean id="configurationManager"
		class="tudu.service.impl.ConfigurationManagerImpl">
		<property name="propertyDAO">
			<ref bean="propertyDAO" />
		</property>
	</bean>

	<aop:config>
		<aop:advisor
			pointcut="execution(* tudu.service.TodoListsManager.*(..))"
			advice-ref="txTodoListsManager" />
		<aop:advisor
			pointcut="execution(* tudu.service.UserManager.*(..))"
			advice-ref="txUserManager" />
		<aop:advisor
			pointcut="execution(* tudu.service.TodosManager.*(..))"
			advice-ref="txTodosManager" />
		<aop:advisor
			pointcut="execution(* tudu.service.ConfigurationManager.*(..))"
			advice-ref="txConfigurationManager" />
	</aop:config>

	<tx:advice id="txUserManager">
		<tx:attributes>
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="*" propagation="REQUIRED" read-only="true" />
		</tx:attributes>
	</tx:advice>

	<tx:advice id="txTodoListsManager">
		<tx:attributes>
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="restore*" propagation="REQUIRED" />
			<tx:method name="*" propagation="REQUIRED" read-only="true" />
		</tx:attributes>
	</tx:advice>

	<tx:advice id="txTodosManager">
		<tx:attributes>
			<tx:method name="create*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="completeTodo*" propagation="REQUIRED" />
			<tx:method name="reopenTodo" propagation="REQUIRED" />
			<tx:method name="*" propagation="REQUIRED" read-only="true" />
		</tx:attributes>
	</tx:advice>

	<tx:advice id="txConfigurationManager">
		<tx:attributes>
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="*" propagation="REQUIRED" read-only="true" />
		</tx:attributes>
	</tx:advice>

	<bean id="tuduListsWebService"
		class="tudu.web.ws.impl.TuduListsWebServiceImpl">

		<property name="todoListsManager">
			<ref bean="todoListsManager" />
		</property>
		<property name="userManager">
			<ref bean="userManager" />
		</property>
	</bean>
</beans>
