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 java.util.Set;
11:
12: import javax.management.MBeanServer;
13:
14: import org.picocontainer.ComponentAdapter;
15: import org.picocontainer.PicoContainer;
16: import org.picocontainer.PicoException;
17: import org.picocontainer.visitors.TraversalCheckingVisitor;
18:
19: /**
20: * traverse pico container and expose components to JNDI on
21: * sight of JNDIExposed
22: * @author k.pribluda
23: */
24: public class JNDIContainerVisitor extends TraversalCheckingVisitor {
25:
26: private PicoContainer container;
27:
28: /**
29: * in case component adapter is JNDIExposed, poke it gently and
30: * it will create component and register it to JNDI if not already
31: * done.
32: */
33: @Override
34: public void visitComponentAdapter(ComponentAdapter componentAdapter) {
35: super .visitComponentAdapter(componentAdapter);
36:
37: if (componentAdapter instanceof JNDIExposed) {
38: componentAdapter.getComponentInstance(container);
39: }
40: }
41:
42: /**
43: * Provides the PicoContainer, that can resolve the components to register as MBean.
44: * @see org.picocontainer.PicoVisitor#visitContainer(org.picocontainer.PicoContainer)
45: */
46: public void visitContainer(final PicoContainer pico) {
47: super .visitContainer(pico);
48: container = pico;
49: }
50:
51: /**
52: * Entry point for the visitor traversal.
53: * @return Returns a {@link Set} with all ObjectInstance instances retrieved from the {@link MBeanServer} for the
54: * registered MBeans.
55: * @see org.picocontainer.visitors.AbstractPicoVisitor#traverse(java.lang.Object)
56: */
57: public Object traverse(final Object node) {
58: super.traverse(node);
59: container = null;
60: return null;
61: }
62:
63: }
|