001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.container.integration.pico;
027:
028: import org.jicarilla.container.Adapter;
029: import org.jicarilla.container.JicarillaClassNotFoundException;
030: import org.jicarilla.container.JicarillaIllegalAccessException;
031: import org.jicarilla.container.JicarillaInstantiationException;
032: import org.jicarilla.container.JicarillaInvocationTargetException;
033: import org.jicarilla.lang.CriterionExposingSelector;
034: import org.jicarilla.lang.OrSelector;
035: import org.jicarilla.lang.Selector;
036: import org.picocontainer.MutablePicoContainer;
037: import org.picocontainer.PicoException;
038:
039: /**
040: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
041: * @version $Id: JicarillaBasedPicoComponentAdapter.java,v 1.2 2004/03/23 13:37:56 lsimons Exp $
042: */
043: public class JicarillaBasedPicoComponentAdapter implements
044: org.picocontainer.ComponentAdapter {
045: final Adapter m_delegate;
046: final Object m_componentKey;
047:
048: public JicarillaBasedPicoComponentAdapter(final Adapter delegate,
049: final Object componentKey) {
050: m_delegate = delegate;
051: m_componentKey = componentKey;
052: }
053:
054: public Object getComponentKey() {
055: if (m_componentKey == null
056: && m_delegate instanceof CriterionExposingSelector) {
057: if (m_delegate instanceof OrSelector) {
058: CriterionExposingSelector selector = ((CriterionExposingSelector) m_delegate);
059:
060: final Selector[] selectors = (Selector[]) selector
061: .getCriterion();
062: if (selectors[0] instanceof CriterionExposingSelector)
063: selector = ((CriterionExposingSelector) selectors[0]);
064:
065: return selector.getCriterion();
066: } else {
067: return ((CriterionExposingSelector) m_delegate)
068: .getCriterion();
069: }
070: }
071:
072: return m_componentKey;
073: }
074:
075: public Class getComponentImplementation() {
076: try {
077: return m_delegate.getInstance().getClass();
078: } catch (JicarillaIllegalAccessException e) {
079: throw new PicoIllegalAccessException(e);
080: } catch (JicarillaInvocationTargetException e) {
081: throw new PicoInvocationTargetException(e);
082: } catch (JicarillaInstantiationException e) {
083: throw new PicoInstantationException(e);
084: } catch (JicarillaClassNotFoundException e) {
085: throw new PicoClassNotFoundException(e);
086: }
087: }
088:
089: public Object getComponentInstance(
090: final MutablePicoContainer dependencyContainer)
091: throws PicoException {
092: try {
093: return m_delegate.getInstance();
094: } catch (JicarillaIllegalAccessException e) {
095: throw new PicoIllegalAccessException(e);
096: } catch (JicarillaInvocationTargetException e) {
097: throw new PicoInvocationTargetException(e);
098: } catch (JicarillaInstantiationException e) {
099: throw new PicoInstantationException(e);
100: } catch (JicarillaClassNotFoundException e) {
101: throw new PicoClassNotFoundException(e);
102: }
103: }
104:
105: public void verify(
106: final org.picocontainer.PicoContainer picoContainer) {
107: /*throw new UnsupportedOperationException(
108: "The PicoContainer verification feature is not supported." );*/
109: }
110: }
|