View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  package ch.elca.el4j.core.contextpassing;
18  
19  import java.util.HashMap;
20  import java.util.Iterator;
21  import java.util.Map;
22  
23  /**
24   * Default implementation of <code>ImplicitContextPassingRegistry</code>. To
25   * register the implicit context passers, their classname is used as id.
26   *
27   * @svnLink $Revision: 3874 $;$Date: 2009-08-04 14:25:40 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/core/contextpassing/DefaultImplicitContextPassingRegistry.java $
28   *
29   * @author Andreas Pfenninger (APR)
30   */
31  public class DefaultImplicitContextPassingRegistry implements
32  		ImplicitContextPassingRegistry {
33  
34  	/** All registered passers. */
35  	private Map<String,ImplicitContextPasser> m_registeredPassers =
36  		new HashMap<String,ImplicitContextPasser>();
37  
38  	/**
39  	 * {@inheritDoc}
40  	 */
41  	public void registerImplicitContextPasser(
42  			ImplicitContextPasser passer) {
43  		String id = passer.getClass().getName();
44  		m_registeredPassers.put(id, passer);
45  	}
46  
47  	/**
48  	 * {@inheritDoc}
49  	 */
50  	public void unregisterImplicitContextPasser(
51  			ImplicitContextPasser passer) {
52  		String id = passer.getClass().getName();
53  		m_registeredPassers.remove(id);
54  	}
55  
56  	/**
57  	 * {@inheritDoc}
58  	 */
59  	public Map<String,Object> getAssembledImplicitContext() {
60  		Map<String,Object> context = new HashMap<String,Object>();
61  		Iterator<String> it = m_registeredPassers.keySet().iterator();
62  		while (it.hasNext()) {
63  			String id = (String) it.next();
64  			ImplicitContextPasser passer
65  				= (ImplicitContextPasser) m_registeredPassers.get(id);
66  			Object ctx = passer.getImplicitlyPassedContext();
67  			context.put(id, ctx);
68  		}
69  		return context;
70  	}
71  
72  	/**
73  	 * {@inheritDoc}
74  	 */
75  	public void pushAssembledImplicitContext(Map<String,Object> contexts) {
76  		Iterator<String> it = m_registeredPassers.keySet().iterator();
77  		while (it.hasNext()) {
78  			String id = (String) it.next();
79  			ImplicitContextPasser passer
80  				= (ImplicitContextPasser) m_registeredPassers.get(id);
81  			Object ctx = contexts.get(id);
82  			passer.pushImplicitlyPassedContext(ctx);
83  		}
84  	}
85  }