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: *****************************************************************************/package org.picocontainer.gems.jndi;
009:
010: import java.io.Serializable;
011:
012: import javax.naming.NamingException;
013:
014: import org.picocontainer.ComponentAdapter;
015: import org.picocontainer.PicoCompositionException;
016: import org.picocontainer.PicoContainer;
017: import org.picocontainer.PicoVisitor;
018:
019: /**
020: * represents dependency provided via JNDI. This dependency is not
021: * to be managed by container at all, so there is no lifecycle, no
022: * monitoring etc.
023: * @author Konstantin Pribluda
024: *
025: */
026: public class JNDIProvided<T> implements ComponentAdapter<T>,
027: Serializable {
028:
029: JNDIObjectReference<T> jndiReference;
030:
031: Object componentKey;
032:
033: /**
034: * create adapter with specified key and reference
035: * @param componentKey component key
036: * @param reference JNDI reference storing component
037: */
038: public JNDIProvided(Object componentKey,
039: JNDIObjectReference<T> reference) {
040: this .componentKey = componentKey;
041: this .jndiReference = reference;
042: }
043:
044: /**
045: * create adapter with JNDI reference. referenced object class will be
046: * takes as key
047: * @param reference JNDI reference storing component
048: */
049: public JNDIProvided(JNDIObjectReference<T> reference) {
050: this (reference.get().getClass(), reference);
051: }
052:
053: /**
054: * create adapter based on JNDI name. I leave this unchecked because
055: * type is really not known at this time
056: * @param jndiName name to be used
057: * @throws NamingException will be thrown if something goes
058: * wrong in JNDI
059: */
060: @SuppressWarnings("unchecked")
061: public JNDIProvided(String jndiName) throws NamingException {
062: this (new JNDIObjectReference(jndiName));
063: }
064:
065: public Object getComponentKey() {
066: return componentKey;
067: }
068:
069: @SuppressWarnings("unchecked")
070: public Class getComponentImplementation() {
071: return jndiReference.get().getClass();
072: }
073:
074: /**
075: * retrieve instance out of JNDI
076: */
077: public T getComponentInstance(PicoContainer container)
078: throws PicoCompositionException {
079: return jndiReference.get();
080: }
081:
082: /**
083: * we have nothing to verify here
084: */
085: public void verify(PicoContainer container)
086: throws PicoCompositionException {
087: }
088:
089: /**
090: * as there is no puprose of proceeding further down,
091: * we do nothing here
092: */
093: public void accept(PicoVisitor visitor) {
094: }
095:
096: public ComponentAdapter<T> getDelegate() {
097: return null;
098: }
099:
100: public <U extends ComponentAdapter> U findAdapterOfType(
101: Class<U> componentAdapterType) {
102: return null;
103: }
104:
105: public String getDescriptor() {
106: return "JNDI(" + jndiReference.getName() + ")";
107: }
108:
109: }
|