01: /*****************************************************************************
02: * Copyright (c) PicoContainer Organization. All rights reserved. *
03: * ------------------------------------------------------------------------- *
04: * The software in this package is published under the terms of the BSD *
05: * style license a copy of which has been included with this distribution in *
06: * the LICENSE.txt file. *
07: * *
08: *****************************************************************************/package org.picocontainer.gems.jndi;
09:
10: import javax.naming.InitialContext;
11: import javax.naming.NamingException;
12:
13: import org.picocontainer.ComponentAdapter;
14: import org.picocontainer.behaviors.Stored;
15:
16: import sun.reflect.ReflectionFactory.GetReflectionFactoryAction;
17:
18: /**
19: * exposes component to JNDI basically does same thing as cached, but uses JNDI
20: * reference instead. Maybe Cached shall be refactored? as there is little new
21: * functionality.
22: *
23: * @author k.pribluda
24: *
25: */
26: public class JNDIExposed<T> extends Stored<T> {
27:
28: /**
29: * construct reference itself using vanilla initial context.
30: * JNDI name is stringified component key
31: * @param delegate
32: * delegate adapter
33:
34: * @throws NamingException
35: */
36: public JNDIExposed(ComponentAdapter<T> delegate)
37: throws NamingException {
38: super (delegate, new JNDIObjectReference<T>(delegate
39: .getComponentKey().toString(), new InitialContext()));
40: }
41:
42: /**
43: * create with provided reference
44: *
45: * @param delegate
46: * @param instanceReference
47: */
48: public JNDIExposed(ComponentAdapter<T> delegate,
49: JNDIObjectReference<T> instanceReference) {
50: super (delegate, instanceReference);
51: }
52:
53: /**
54: * create adapter with desired name
55: * @param delegate
56: * @param name
57: * @throws NamingException
58: */
59: public JNDIExposed(ComponentAdapter<T> delegate, String name)
60: throws NamingException {
61: super (delegate, new JNDIObjectReference<T>(name,
62: new InitialContext()));
63: }
64:
65: public String toString() {
66: return "JNDI" + instanceReference.toString() + super.toString();
67: }
68: }
|