KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > gems > adapters > 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.adapters;
11
12 import org.picocontainer.PicoContainer;
13 import org.picocontainer.PicoInitializationException;
14 import org.picocontainer.PicoIntrospectionException;
15 import org.picocontainer.PicoVerificationException;
16 import org.picocontainer.defaults.AbstractComponentAdapter;
17
18
19 /**
20  * Component adapter that wrapps a static factory with the help of {@link StaticFactory}.
21  *
22  * @author Jörg Schaible
23  * @author Leo Simmons
24  * @since 1.1
25  */

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

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

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

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

66     public void verify(PicoContainer container) throws PicoVerificationException {
67     }
68 }
Popular Tags