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.JicarillaClassNotFoundException;
029: import org.jicarilla.container.JicarillaIllegalAccessException;
030: import org.jicarilla.container.JicarillaInstantiationException;
031: import org.jicarilla.container.JicarillaInvocationTargetException;
032: import org.jicarilla.container.Resolver;
033: import org.jicarilla.container.UnsatisfiableDependencyException;
034: import org.jicarilla.lang.Assert;
035: import org.picocontainer.ComponentAdapter;
036: import org.picocontainer.MutablePicoContainer;
037: import org.picocontainer.Parameter;
038: import org.picocontainer.PicoException;
039: import org.picocontainer.PicoIntrospectionException;
040: import org.picocontainer.PicoRegistrationException;
041: import org.picocontainer.PicoVerificationException;
042: import org.picocontainer.defaults.InstanceComponentAdapter;
043:
044: import java.util.Collection;
045: import java.util.HashSet;
046: import java.util.List;
047: import java.util.Set;
048:
049: /**
050: *
051: *
052: * @author <a href="mail at leosimons dot com">Leo Simons</a>
053: * @version $Id: ResolverBasedPicoContainer.java,v 1.2 2004/03/23 13:37:56 lsimons Exp $
054: */
055: public class ResolverBasedPicoContainer implements MutablePicoContainer {
056: protected final Resolver m_delegate;
057:
058: public ResolverBasedPicoContainer(final Resolver delegate) {
059: Assert.assertNotNull("delegate argument may not be null",
060: delegate);
061: m_delegate = delegate;
062: }
063:
064: public ComponentAdapter registerComponentImplementation(
065: final Object componentKey,
066: final Class componentImplementation)
067: throws PicoRegistrationException {
068: throw new UnsupportedOperationException();
069: }
070:
071: public ComponentAdapter registerComponentImplementation(
072: final Object componentKey,
073: final Class componentImplementation,
074: final Parameter[] parameters)
075: throws PicoRegistrationException {
076: throw new UnsupportedOperationException();
077: }
078:
079: public ComponentAdapter registerComponentImplementation(
080: final Class componentImplementation)
081: throws PicoRegistrationException {
082: throw new UnsupportedOperationException();
083: }
084:
085: public ComponentAdapter registerComponentInstance(
086: final Object componentInstance)
087: throws PicoRegistrationException {
088: throw new UnsupportedOperationException();
089: }
090:
091: public ComponentAdapter registerComponentInstance(
092: final Object componentKey, final Object componentInstance)
093: throws PicoRegistrationException {
094: throw new UnsupportedOperationException();
095: }
096:
097: public final void registerComponent(
098: final ComponentAdapter componentAdapter)
099: throws PicoRegistrationException {
100: throw new UnsupportedOperationException();
101: }
102:
103: public ComponentAdapter unregisterComponent(
104: final Object componentKey) {
105: throw new UnsupportedOperationException();
106: }
107:
108: public void registerOrderedComponentAdapter(
109: final ComponentAdapter componentAdapter) {
110: //throw new UnsupportedOperationException();
111: }
112:
113: public void addOrderedComponentAdapter(
114: final ComponentAdapter componentAdapter) {
115: /*throw new UnsupportedOperationException();*/
116: }
117:
118: public boolean addChild(final MutablePicoContainer child) {
119: throw new UnsupportedOperationException();
120: }
121:
122: public boolean addParent(final MutablePicoContainer parent) {
123: throw new UnsupportedOperationException();
124: }
125:
126: public boolean removeChild(final MutablePicoContainer child) {
127: throw new UnsupportedOperationException();
128: }
129:
130: public boolean removeParent(final MutablePicoContainer parent) {
131: throw new UnsupportedOperationException();
132: }
133:
134: public Object getComponentInstance(final Object componentKey)
135: throws PicoException {
136: try {
137: return m_delegate.get(componentKey);
138: } catch (JicarillaIllegalAccessException e) {
139: throw new PicoIllegalAccessException(e);
140: } catch (JicarillaInvocationTargetException e) {
141: throw new PicoInvocationTargetException(e);
142: } catch (JicarillaInstantiationException e) {
143: throw new PicoInstantationException(e);
144: } catch (JicarillaClassNotFoundException e) {
145: throw new PicoClassNotFoundException(e);
146: }
147: }
148:
149: public List getComponentInstances() throws PicoException {
150: throw new UnsupportedOperationException();
151: }
152:
153: public List getUnmanagedComponentInstances() throws PicoException {
154: throw new UnsupportedOperationException();
155: }
156:
157: public boolean hasComponent(final Object componentKey) {
158: return m_delegate.contains(componentKey);
159: }
160:
161: public Collection getComponentKeys() {
162: throw new UnsupportedOperationException();
163: }
164:
165: public Collection getChildContainers() {
166: throw new UnsupportedOperationException();
167: }
168:
169: public List getParentContainers() {
170: throw new UnsupportedOperationException();
171: }
172:
173: public ComponentAdapter findComponentAdapter(
174: final Object componentKey)
175: throws PicoIntrospectionException {
176: Object instance = m_delegate.get(componentKey);
177: if (instance == null) {
178: Set unsatisfiedDeps = new HashSet();
179: unsatisfiedDeps.add(componentKey);
180:
181: throw new UnsatisfiableDependencyException(Resolver.class,
182: unsatisfiedDeps);
183: }
184: return new InstanceComponentAdapter(componentKey, instance);
185: }
186:
187: public void verify() throws PicoVerificationException {
188: /*throw new UnsupportedOperationException();*/
189: }
190: }
|