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 * Idea by Rachel Davies, Original code by various * 009 *****************************************************************************/ 010 package org.nanocontainer.aop.defaults; 011 012 import org.nanocontainer.aop.AspectsApplicator; 013 import org.picocontainer.ComponentAdapter; 014 import org.picocontainer.Parameter; 015 import org.picocontainer.PicoIntrospectionException; 016 import org.picocontainer.defaults.AssignabilityRegistrationException; 017 import org.picocontainer.defaults.ComponentAdapterFactory; 018 import org.picocontainer.defaults.DecoratingComponentAdapterFactory; 019 import org.picocontainer.defaults.DefaultComponentAdapterFactory; 020 import org.picocontainer.defaults.NotConcreteRegistrationException; 021 022 /** 023 * Produces component adapters that apply aspects to components. 024 * 025 * @author Stephen Molitor 026 * @version $Revision: 3144 $ 027 */ 028 public class AspectsComponentAdapterFactory extends DecoratingComponentAdapterFactory { 029 030 private final AspectsApplicator aspectsApplicator; 031 032 /** 033 * Creates a new <code>AspectsComponentAdapterFactory</code>. The factory 034 * will produce <code>AspectsComponentAdapter</code> objects that will use 035 * <code>aspectsApplicator</code> to apply aspects to components produced 036 * by <code>delegate</code>. 037 * 038 * @param aspectsApplicator used to apply the aspects. 039 * @param delegate the real component adapter factory that this factory 040 * delegates to. 041 */ 042 public AspectsComponentAdapterFactory(AspectsApplicator aspectsApplicator, ComponentAdapterFactory delegate) { 043 super(delegate); 044 this.aspectsApplicator = aspectsApplicator; 045 } 046 047 /** 048 * Creates a new <code>AspectsComponentAdapterFactory</code>. The factory 049 * will produce <code>AspectsComponentAdapter</code> objects that will use 050 * <code>aspectsApplicator</code> to apply aspects to components produced 051 * by a 052 * <code>org.picocontainer.defaults.DefaultComponentAdapterFactory</code>. 053 * 054 * @param aspectsApplicator used to apply the aspects. 055 */ 056 public AspectsComponentAdapterFactory(AspectsApplicator aspectsApplicator) { 057 this(aspectsApplicator, new DefaultComponentAdapterFactory()); 058 } 059 060 public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, 061 Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, 062 NotConcreteRegistrationException { 063 return new AspectsComponentAdapter(aspectsApplicator, super.createComponentAdapter(componentKey, 064 componentImplementation, parameters)); 065 } 066 067 }