@@ -19,8 +19,11 @@ package org.springframework.scala.beans.factory.function
1919import org .springframework .beans .factory .config .DestructionAwareBeanPostProcessor
2020import org .springframework .core .PriorityOrdered
2121import scala .reflect .BeanProperty
22- import org .springframework .util .Assert
23- import scala .collection .mutable .{Set , MultiMap , SynchronizedMap , HashMap }
22+ import org .springframework .util .{StringUtils , Assert }
23+ import scala .collection .mutable .{ListBuffer , SynchronizedMap , HashMap }
24+ import scala .Predef ._
25+ import scala .AnyRef
26+ import scala .Some
2427
2528/**
2629 * [[org.springframework.beans.factory.config.BeanPostProcessor ]] implementation
@@ -39,13 +42,11 @@ import scala.collection.mutable.{Set, MultiMap, SynchronizedMap, HashMap}
3942class InitDestroyFunctionBeanPostProcessor
4043 extends DestructionAwareBeanPostProcessor with PriorityOrdered {
4144
42- val initFunctions = new HashMap [String , Set [Function1 [Any , Unit ]]]
43- with MultiMap [String , Function1 [Any , Unit ]]
44- with SynchronizedMap [String , Set [Function1 [Any , Unit ]]]
45+ val initFunctions = new HashMap [String , ListBuffer [Function1 [Any , Unit ]]]
46+ with SynchronizedMap [String , ListBuffer [Function1 [Any , Unit ]]]
4547
46- val destroyFunctions = new HashMap [String , Set [Function1 [Any , Unit ]]]
47- with MultiMap [String , Function1 [Any , Unit ]]
48- with SynchronizedMap [String , Set [Function1 [Any , Unit ]]]
48+ val destroyFunctions = new HashMap [String , ListBuffer [Function1 [Any , Unit ]]]
49+ with SynchronizedMap [String , ListBuffer [Function1 [Any , Unit ]]]
4950
5051 @ BeanProperty
5152 var order : Int = org.springframework.core.Ordered .LOWEST_PRECEDENCE
@@ -61,10 +62,10 @@ class InitDestroyFunctionBeanPostProcessor
6162 * @tparam T the bean type
6263 */
6364 def registerInitFunction [T ](beanName : String , initFunction : (T ) => Unit ) {
64- Assert .hasLength(beanName, " 'beanName' must not be empty" )
65- Assert .notNull (initFunction, " 'initFunction' must not be null" )
65+ assert( StringUtils .hasLength(beanName) , " 'beanName' must not be empty" )
66+ assert (initFunction != null , " 'initFunction' must not be null" )
6667
67- initFunctions.addBinding( beanName, initFunction.asInstanceOf [Function1 [Any , Unit ]])
68+ addFunction(initFunctions, beanName, initFunction.asInstanceOf [Function1 [Any , Unit ]])
6869 }
6970
7071 /**
@@ -81,8 +82,21 @@ class InitDestroyFunctionBeanPostProcessor
8182 Assert .hasLength(beanName, " 'beanName' must not be empty" )
8283 Assert .notNull(destroyFunction, " 'destroyFunction' must not be null" )
8384
84- destroyFunctions
85- .addBinding(beanName, destroyFunction.asInstanceOf [Function1 [Any , Unit ]])
85+ addFunction(destroyFunctions, beanName, destroyFunction.asInstanceOf [Function1 [Any , Unit ]])
86+ }
87+
88+ private def addFunction (functionsMap : HashMap [String , ListBuffer [Function1 [Any , Unit ]]],
89+ beanName : String ,
90+ function : (Any ) => Unit ) {
91+
92+ functionsMap.get(beanName) match {
93+ case None =>
94+ val list = new ListBuffer [Function1 [Any , Unit ]]
95+ list += function
96+ functionsMap(beanName) = list
97+ case Some (list) =>
98+ list += function
99+ }
86100 }
87101
88102 def postProcessBeforeInitialization (bean : AnyRef , beanName : String ): AnyRef = {
0 commit comments