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: * Original code by Leo Simmons & Jörg Schaible *
09: *****************************************************************************/package org.picocontainer.gems.adapters;
10:
11: import org.picocontainer.PicoContainer;
12: import org.picocontainer.PicoCompositionException;
13: import org.picocontainer.PicoVerificationException;
14: import org.picocontainer.adapters.AbstractAdapter;
15:
16: /**
17: * Component adapter that wrapps a static factory with the help of {@link StaticFactory}.
18: *
19: * @author Jörg Schaible
20: * @author Leo Simmons
21: */
22: public final class StaticFactoryAdapter extends AbstractAdapter {
23: private final StaticFactory staticFactory;
24:
25: /**
26: * Construct a ComponentAdapter accessing a static factory creating the component.
27: *
28: * @param type The type of the created component.
29: * @param staticFactory Wrapper instance for the static factory.
30: */
31: public StaticFactoryAdapter(Class type, StaticFactory staticFactory) {
32:
33: this (type, type, staticFactory);
34: }
35:
36: /**
37: * Construct a ComponentAdapter accessing a static factory creating the component using a special key for addComponent
38: * registration.
39: *
40: * @param componentKey The key of the created component.
41: * @param type The type of the created component.
42: * @param staticFactory Wrapper instance for the static factory.
43: */
44: public StaticFactoryAdapter(Object componentKey, Class type,
45: StaticFactory staticFactory) {
46: super (componentKey, type);
47: this .staticFactory = staticFactory;
48: }
49:
50: /**
51: * @return Returns the component created by the static factory.
52: * @see org.picocontainer.ComponentAdapter#getComponentInstance(org.picocontainer.PicoContainer)
53: */
54: public Object getComponentInstance(PicoContainer container)
55: throws PicoCompositionException {
56: return staticFactory.get();
57: }
58:
59: /**
60: * {@inheritDoc}
61: *
62: * @see org.picocontainer.ComponentAdapter#verify(org.picocontainer.PicoContainer)
63: */
64: public void verify(PicoContainer container)
65: throws PicoVerificationException {
66: }
67:
68: public String getDescriptor() {
69: return "StaticFactory";
70: }
71: }
|