|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| CustomizedComponentAdapter.java | - | 75% | 71.4% | 73.3% |
|
||||||||||||||
| 1 | // | |
| 2 | // Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. | |
| 3 | // All rights reserved. | |
| 4 | // | |
| 5 | // Redistribution and use in source and binary forms, with or without modification, | |
| 6 | // are permitted provided that the following conditions are met: | |
| 7 | // | |
| 8 | // * Redistributions of source code must retain the above copyright notice, | |
| 9 | // this list of conditions and the following disclaimer. | |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, | |
| 11 | // this list of conditions and the following disclaimer in the documentation | |
| 12 | // and/or other materials provided with the distribution. | |
| 13 | // * Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J. | |
| 14 | // nor the names of its contributors may be used to endorse or promote products | |
| 15 | // derived from this software without specific prior written permission. | |
| 16 | // | |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
| 20 | // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 21 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 22 | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 23 | // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 24 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 25 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 26 | // POSSIBILITY OF SUCH DAMAGE. | |
| 27 | // | |
| 28 | ||
| 29 | package org.objectledge.pico.customization; | |
| 30 | ||
| 31 | import org.picocontainer.ComponentAdapter; | |
| 32 | import org.picocontainer.PicoContainer; | |
| 33 | import org.picocontainer.PicoInitializationException; | |
| 34 | import org.picocontainer.PicoIntrospectionException; | |
| 35 | import org.picocontainer.PicoVerificationException; | |
| 36 | import org.picocontainer.PicoVisitor; | |
| 37 | ||
| 38 | /** | |
| 39 | * An adapter for a component that is customized on behalf of a component that is asking for it. | |
| 40 | * <p> | |
| 41 | * When another component is being initialized and it depends on the component that is managed by | |
| 42 | * this adapter (identified by the componentKey), the customizedContainerProvider is asked to | |
| 43 | * produce an instance of the customized component. Thus, different components may recieve different | |
| 44 | * instnaces of the managed component, depending on the customizedComponentProvider's semantics. | |
| 45 | * </p> | |
| 46 | * | |
| 47 | * @author <a href="Rafal.Krzewski">rafal@caltha.pl </a> | |
| 48 | * @version $Id: CustomizedComponentAdapter.java,v 1.15 2005/02/04 02:28:00 rafal Exp $ | |
| 49 | */ | |
| 50 | public class CustomizedComponentAdapter | |
| 51 | implements ComponentAdapter | |
| 52 | { | |
| 53 | private Object componentKey; | |
| 54 | ||
| 55 | private CustomizedComponentProvider customizedComponentProvider; | |
| 56 | ||
| 57 | /** | |
| 58 | * Crates a new instance of the adapter. | |
| 59 | * | |
| 60 | * @param componentKey the component key this adapter manages. | |
| 61 | * @param customizedComponentProvider a provider of customized components. | |
| 62 | */ | |
| 63 | 860 | public CustomizedComponentAdapter(Object componentKey, |
| 64 | CustomizedComponentProvider customizedComponentProvider) | |
| 65 | { | |
| 66 | 860 | this.componentKey = componentKey; |
| 67 | 860 | this.customizedComponentProvider = customizedComponentProvider; |
| 68 | } | |
| 69 | ||
| 70 | /** | |
| 71 | * {@inheritDoc} | |
| 72 | */ | |
| 73 | 0 | public Object getComponentInstance(PicoContainer container) |
| 74 | throws PicoInitializationException, PicoIntrospectionException | |
| 75 | { | |
| 76 | // lacking a better idea... | |
| 77 | 0 | return customizedComponentProvider.getCustomizedComponentInstance(container, null, null); |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * Returns a customized components instance. | |
| 82 | * <p> | |
| 83 | * This method is called by the {@link CustomizingConstructorComponentAdapter}. | |
| 84 | * </p> | |
| 85 | * | |
| 86 | * @param container the container for resolving references. | |
| 87 | * @param componentKey the key of the requesting component. | |
| 88 | * @param componentImplementation the implemenation class of the requesting component. | |
| 89 | * @return a customized component instance. | |
| 90 | * @throws PicoInitializationException if the customized component cannot be instantiated. | |
| 91 | * @throws PicoIntrospectionException if there is a problem introspecting classes. | |
| 92 | * @throws UnsupportedKeyTypeException if the requesting component key if an unsupported type. | |
| 93 | */ | |
| 94 | 688 | public Object getComponentInstance(PicoContainer container, Object componentKey, |
| 95 | Class componentImplementation) | |
| 96 | throws PicoInitializationException, PicoIntrospectionException, UnsupportedKeyTypeException | |
| 97 | { | |
| 98 | 688 | return customizedComponentProvider.getCustomizedComponentInstance(container, componentKey, |
| 99 | componentImplementation); | |
| 100 | } | |
| 101 | ||
| 102 | /** | |
| 103 | * {@inheritDoc} | |
| 104 | */ | |
| 105 | 86 | public void verify(PicoContainer container) |
| 106 | throws PicoVerificationException | |
| 107 | { | |
| 108 | 86 | customizedComponentProvider.verify(container); |
| 109 | } | |
| 110 | ||
| 111 | /** | |
| 112 | * {@inheritDoc} | |
| 113 | */ | |
| 114 | 1376 | public Class getComponentImplementation() |
| 115 | { | |
| 116 | 1376 | return customizedComponentProvider.getCustomizedComponentImplementation(); |
| 117 | } | |
| 118 | ||
| 119 | /** | |
| 120 | * {@inheritDoc} | |
| 121 | */ | |
| 122 | 2236 | public Object getComponentKey() |
| 123 | { | |
| 124 | 2236 | return componentKey; |
| 125 | } | |
| 126 | ||
| 127 | /** | |
| 128 | * {@inheritDoc} | |
| 129 | */ | |
| 130 | 0 | public void accept(PicoVisitor visitor) |
| 131 | { | |
| 132 | 0 | visitor.visitComponentAdapter(this); |
| 133 | } | |
| 134 | } |
|
||||||||||