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 * Original code by *
009 *****************************************************************************/
010 package org.picocontainer.behaviors;
011
012
013 import org.picocontainer.ComponentAdapter;
014 import org.picocontainer.PicoContainer;
015 import org.picocontainer.PicoCompositionException;
016
017 import java.util.concurrent.locks.Lock;
018 import java.util.concurrent.locks.ReentrantLock;
019
020 /**
021 * @author Paul Hammant
022 */
023 public class Locked extends AbstractBehavior {
024 private Lock lock = new ReentrantLock();
025
026 public Locked(ComponentAdapter delegate) {
027 super(delegate);
028 }
029
030 public Object getComponentInstance(PicoContainer container) throws PicoCompositionException {
031 Object retVal = null;
032 lock.lock();
033 try {
034 retVal = super.getComponentInstance(container);
035 }
036 finally {
037 lock.unlock();
038 }
039 return retVal;
040 }
041 public String toString() {
042 return "Locked:" + super.toString();
043 }
044
045 }