|
PicoContainer example source code file (BasicComponentParameter.java)
The PicoContainer BasicComponentParameter.java source code
/*****************************************************************************
* Copyright (C) PicoContainer Organization. All rights reserved. *
* ------------------------------------------------------------------------- *
* The software in this package is published under the terms of the BSD *
* style license a copy of which has been included with this distribution in *
* the LICENSE.txt file. *
* *
* Original code by *
*****************************************************************************/
package org.picocontainer.parameters;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.Parameter;
import org.picocontainer.ParameterName;
import org.picocontainer.PicoContainer;
import org.picocontainer.PicoVisitor;
import org.picocontainer.injectors.AbstractInjector;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* A BasicComponentParameter should be used to pass in a particular component as argument to a
* different component's constructor. This is particularly useful in cases where several
* components of the same type have been registered, but with a different key. Passing a
* ComponentParameter as a parameter when registering a component will give PicoContainer a hint
* about what other component to use in the constructor. This Parameter will never resolve
* against a collecting type, that is not directly registered in the PicoContainer itself.
*
* @author Jon Tirsén
* @author Aslak Hellesøy
* @author Jörg Schaible
* @author Thomas Heller
* @version $Revision: 3686 $
*/
public class BasicComponentParameter
implements Parameter, Serializable
{
/** <code>BASIC_DEFAULT is an instance of BasicComponentParameter using the default constructor. */
public static final BasicComponentParameter BASIC_DEFAULT = new BasicComponentParameter();
private Object componentKey;
/**
* Expect a parameter matching a component of a specific key.
*
* @param componentKey the key of the desired addComponent
*/
public BasicComponentParameter(Object componentKey) {
this.componentKey = componentKey;
}
/** Expect any paramter of the appropriate type. */
public BasicComponentParameter() {
}
/**
* Check wether the given Parameter can be statisfied by the container.
*
* @return <code>true if the Parameter can be verified.
*
* @throws org.picocontainer.PicoCompositionException
* {@inheritDoc}
* @see org.picocontainer.Parameter#isResolvable(org.picocontainer.PicoContainer,org.picocontainer.ComponentAdapter,Class,org.picocontainer.ParameterName)
*/
public boolean isResolvable(PicoContainer container,
ComponentAdapter adapter,
Class expectedType,
ParameterName expectedParameterName)
{
return resolveAdapter(container, adapter, (Class<?>)expectedType, expectedParameterName) != null;
}
public Object resolveInstance(PicoContainer container,
ComponentAdapter adapter,
Class expectedType,
ParameterName expectedParameterName)
{
final ComponentAdapter componentAdapter =
resolveAdapter(container, adapter, (Class<?>)expectedType, expectedParameterName);
if (componentAdapter != null) {
return container.getComponent(componentAdapter.getComponentKey());
}
return null;
}
public void verify(PicoContainer container,
ComponentAdapter adapter,
Class expectedType,
ParameterName expectedParameterName)
{
final ComponentAdapter componentAdapter =
resolveAdapter(container, adapter, (Class<?>)expectedType, expectedParameterName);
if (componentAdapter == null) {
final Set<Class> set = new HashSet
Other PicoContainer examples (source code examples)Here is a short list of links related to this PicoContainer BasicComponentParameter.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.