001 /***************************************************************************** 002 * Copyright (C) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 * * 008 *****************************************************************************/ 009 package org.picocontainer.references; 010 011 import org.picocontainer.ObjectReference; 012 013 import java.util.Map; 014 015 /** @author Paul Hammant */ 016 public class ThreadLocalMapObjectReference implements ObjectReference { 017 private final ThreadLocal threadLocal; 018 private final Object componentKey; 019 020 public ThreadLocalMapObjectReference(ThreadLocal threadLocal, Object componentKey) { 021 this.threadLocal = threadLocal; 022 this.componentKey = componentKey; 023 } 024 025 public Object get() { 026 return ((Map)threadLocal.get()).get(componentKey) ; 027 } 028 029 public void set(Object item) { 030 ((Map)threadLocal.get()).put(componentKey, item) ; 031 032 } 033 }