001 /***************************************************************************** 002 * Copyright (C) PicoContainer Organization. All rights reserved. * 003 * ------------------------------------------------------------------------- * 004 * The software in this package is published under the terms of the BSD * 005 * style license a copy of which has been included with this distribution in * 006 * the LICENSE.txt file. * 007 * * 008 * Original code by Leo Simmons & J?rg Schaible * 009 *****************************************************************************/ 010 package org.picocontainer.gems.adapters; 011 012 import org.picocontainer.PicoContainer; 013 import org.picocontainer.PicoInitializationException; 014 import org.picocontainer.PicoIntrospectionException; 015 import org.picocontainer.PicoVerificationException; 016 import org.picocontainer.defaults.AbstractComponentAdapter; 017 018 019 /** 020 * Component adapter that wrapps a static factory with the help of {@link StaticFactory}. 021 * 022 * @author Jörg Schaible 023 * @author Leo Simmons 024 * @since 1.1 025 */ 026 public class StaticFactoryComponentAdapter extends AbstractComponentAdapter { 027 private StaticFactory staticFactory; 028 029 /** 030 * Construct a ComponentAdapter accessing a static factory creating the component. 031 * 032 * @param type The type of the created component. 033 * @param staticFactory Wrapper instance for the static factory. 034 */ 035 public StaticFactoryComponentAdapter(Class type, StaticFactory staticFactory) { 036 037 this(type, type, staticFactory); 038 } 039 040 /** 041 * Construct a ComponentAdapter accessing a static factory creating the component using a special key for component 042 * registration. 043 * 044 * @param componentKey The key of the created component. 045 * @param type The type of the created component. 046 * @param staticFactory Wrapper instance for the static factory. 047 */ 048 public StaticFactoryComponentAdapter(Object componentKey, Class type, StaticFactory staticFactory) { 049 super(componentKey, type); 050 this.staticFactory = staticFactory; 051 } 052 053 /** 054 * @return Returns the component created by the static factory. 055 * @see org.picocontainer.ComponentAdapter#getComponentInstance(org.picocontainer.PicoContainer) 056 */ 057 public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException { 058 return staticFactory.get(); 059 } 060 061 /** 062 * {@inheritDoc} 063 * 064 * @see org.picocontainer.ComponentAdapter#verify(org.picocontainer.PicoContainer) 065 */ 066 public void verify(PicoContainer container) throws PicoVerificationException { 067 } 068 }