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
010package org.picocontainer.gems.jndi;
011
012import java.util.Properties;
013
014import javax.naming.NamingException;
015
016import org.picocontainer.ComponentAdapter;
017import org.picocontainer.ComponentMonitor;
018import org.picocontainer.LifecycleStrategy;
019import org.picocontainer.Parameter;
020import org.picocontainer.PicoCompositionException;
021import org.picocontainer.behaviors.AbstractBehaviorFactory;
022
023/**
024 * produce JNDI exposing behaviour
025 * 
026 * @author Konstantin Pribluda
027 * 
028 * @param <T>
029 */
030@SuppressWarnings("serial")
031public class JNDIExposing extends AbstractBehaviorFactory {
032
033        @Override
034        public <T> ComponentAdapter<T> addComponentAdapter(
035                        final ComponentMonitor componentMonitor,
036                        final LifecycleStrategy lifecycleStrategy,
037                        final Properties componentProperties, final ComponentAdapter<T> adapter) {
038                try {
039                        return new JNDIExposed<T>(super.addComponentAdapter(
040                                        componentMonitor, lifecycleStrategy, componentProperties,
041                                        adapter));
042                } catch (NamingException e) {
043                        throw new PicoCompositionException(
044                                        "unable to create JNDI behaviour", e);
045                }
046        }
047
048        @Override
049        public <T> ComponentAdapter<T> createComponentAdapter(
050                        final ComponentMonitor componentMonitor,
051                        final LifecycleStrategy lifecycleStrategy,
052                        final Properties componentProperties, final Object componentKey,
053                        final Class<T> componentImplementation, final Parameter... parameters)
054                        throws PicoCompositionException {
055                // TODO Auto-generated method stub
056                ComponentAdapter<T> componentAdapter = super.createComponentAdapter(
057                                componentMonitor, lifecycleStrategy, componentProperties,
058                                componentKey, componentImplementation, parameters);
059
060                try {
061                        return new JNDIExposed<T>(componentAdapter);
062                } catch (NamingException e) {
063                        throw new PicoCompositionException(
064                                        "unable to create JNDI behaviour", e);
065                }
066        }
067
068}