KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > gems > StaticFactoryComponentAdapter


1 /*****************************************************************************
2  * Copyright (C) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  * *
8  * Original code by Leo Simmons & Jörg Schaible *
9  *****************************************************************************/

10 package org.picocontainer.gems;
11 import org.picocontainer.PicoContainer;
12 import org.picocontainer.PicoInitializationException;
13 import org.picocontainer.PicoIntrospectionException;
14 import org.picocontainer.PicoVerificationException;
15 import org.picocontainer.defaults.AbstractComponentAdapter;
16
17
18 /**
19  * Component adapter that wrapps a static factory with the help of {@link StaticFactory}.
20  * @author Jörg Schaible
21  * @author Leo Simmons
22  * @since 1.1
23  */

24 public class StaticFactoryComponentAdapter
25         extends AbstractComponentAdapter {
26     private StaticFactory staticFactory;
27
28     /**
29      * Construct a ComponentAdapter accessing a static factory creating the component.
30      *
31      * @param type The type of the created component.
32      * @param staticFactory Wrapper instance for the static factory.
33      */

34     public StaticFactoryComponentAdapter(Class JavaDoc type, StaticFactory staticFactory) {
35
36         this(type, type, staticFactory);
37     }
38
39     /**
40      * Construct a ComponentAdapter accessing a static factory creating the component
41      * using a special key for component registration.
42      *
43      * @param type The type of the created component.
44      * @param staticFactory Wrapper instance for the static factory.
45      */

46     public StaticFactoryComponentAdapter(Object JavaDoc componentKey, Class JavaDoc type, StaticFactory staticFactory) {
47         super(componentKey, type);
48         this.staticFactory = staticFactory;
49     }
50
51     /**
52      * @return Returns the component created by the static factory.
53      * @see org.picocontainer.ComponentAdapter#getComponentInstance(org.picocontainer.PicoContainer)
54      */

55     public Object JavaDoc getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException {
56         return staticFactory.get();
57     }
58
59     /**
60      * {@inheritDoc}
61      * @see org.picocontainer.ComponentAdapter#verify(org.picocontainer.PicoContainer)
62      */

63     public void verify(PicoContainer container) throws PicoVerificationException {
64     }
65 }
Popular Tags