org.apache.cocoon.spring.configurator.impl
Class BeanMap

java.lang.Object
  extended by org.apache.cocoon.spring.configurator.impl.BeanMap
All Implemented Interfaces:
Map<Object,Object>, BeanFactoryAware
Direct Known Subclasses:
WildcardBeanMap

public class BeanMap
extends Object
implements Map<Object,Object>, BeanFactoryAware

This is a map implementation collecting all beans of a specific type (class) from a spring bean factory. The beans are available through their configured bean id. The map has a lazy implementation: the beans are not searched on instantiation but the first time the map is accessed. This avoids any startup ordering problems. By default the map searches in the bean factory it is used in and in all the parent bean factories (if there are any). This behaviour can be changed by calling the setCheckParent(boolean) method.

Since:
1.0.1
Version:
$Id: BeanMap.java 754972 2009-03-16 18:20:54Z reinhard $

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Class<?> beanClass
          The class for all beans in this map.
protected  ListableBeanFactory beanFactory
          The bean factory.
protected  Map<Object,Object> beanMap
          The real map.
protected  boolean checkParent
          Do we check the parent factories?
protected  List<String> hasProperties
          Do we check for properties?
protected  boolean initialized
          Is the map initialized?
protected  String keyProperty
          Which property should we use to key the map?
protected  boolean stripPrefix
          Do we strip the prefix from the bean name?
 
Constructor Summary
BeanMap()
           
 
Method Summary
protected  void checkInit()
          Check if the bean is already initialized.
 void clear()
           
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
 Set<Map.Entry<Object,Object>> entrySet()
           
 boolean equals(Object obj)
           
 Object get(Object key)
           
protected  void getBeanNames(ListableBeanFactory factory, Set<String> beanNames)
          Get all bean names for the given type.
 int hashCode()
           
 boolean isEmpty()
           
 Set<Object> keySet()
           
protected  void load(Set<String> beanNames)
          Get all the beans from the bean factory and put them into a map using their id.
protected  String[] lookupBeans(ListableBeanFactory factory)
           
 Object put(Object key, Object value)
           
 void putAll(Map<?,?> t)
           
 Object remove(Object key)
           
 void setBeanFactory(BeanFactory factory)
           
 void setCheckParent(boolean checkParent)
           
 void setHasProperties(String pHasProperties)
           
 void setKeyProperty(String pKeyProperty)
           
 void setStripPrefix(boolean stripPrefix)
           
 void setType(Class<?> typeClass)
           
 int size()
           
protected  Object stripPrefix(String beanName)
           
 String toString()
           
 Collection<Object> values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

beanMap

protected final Map<Object,Object> beanMap
The real map.


initialized

protected boolean initialized
Is the map initialized?


beanFactory

protected ListableBeanFactory beanFactory
The bean factory.


beanClass

protected Class<?> beanClass
The class for all beans in this map.


stripPrefix

protected boolean stripPrefix
Do we strip the prefix from the bean name?


checkParent

protected boolean checkParent
Do we check the parent factories?


hasProperties

protected List<String> hasProperties
Do we check for properties?


keyProperty

protected String keyProperty
Which property should we use to key the map?

Constructor Detail

BeanMap

public BeanMap()
Method Detail

load

protected void load(Set<String> beanNames)
Get all the beans from the bean factory and put them into a map using their id.

Parameters:
beanNames - The bean names to load.

stripPrefix

protected Object stripPrefix(String beanName)

checkInit

protected void checkInit()
Check if the bean is already initialized. If not, the bean's are searched in the bean factory.


getBeanNames

protected void getBeanNames(ListableBeanFactory factory,
                            Set<String> beanNames)
Get all bean names for the given type.

Parameters:
factory - The bean factory.
beanNames - The set containing the resulting bean names.

lookupBeans

protected String[] lookupBeans(ListableBeanFactory factory)

setBeanFactory

public void setBeanFactory(BeanFactory factory)
                    throws BeansException
Specified by:
setBeanFactory in interface BeanFactoryAware
Throws:
BeansException
See Also:
BeanFactoryAware.setBeanFactory(org.springframework.beans.factory.BeanFactory)

setStripPrefix

public void setStripPrefix(boolean stripPrefix)

setCheckParent

public void setCheckParent(boolean checkParent)

setHasProperties

public void setHasProperties(String pHasProperties)

setKeyProperty

public void setKeyProperty(String pKeyProperty)

setType

public void setType(Class<?> typeClass)

clear

public void clear()
Specified by:
clear in interface Map<Object,Object>
See Also:
Map.clear()

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<Object,Object>
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<Object,Object>
See Also:
Map.containsValue(java.lang.Object)

entrySet

public Set<Map.Entry<Object,Object>> entrySet()
Specified by:
entrySet in interface Map<Object,Object>
See Also:
Map.entrySet()

get

public Object get(Object key)
Specified by:
get in interface Map<Object,Object>
See Also:
Map.get(java.lang.Object)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<Object,Object>
See Also:
Map.isEmpty()

keySet

public Set<Object> keySet()
Specified by:
keySet in interface Map<Object,Object>
See Also:
Map.keySet()

put

public Object put(Object key,
                  Object value)
Specified by:
put in interface Map<Object,Object>
See Also:
Map.put(java.lang.Object, java.lang.Object)

putAll

public void putAll(Map<?,?> t)
Specified by:
putAll in interface Map<Object,Object>
See Also:
Map.putAll(java.util.Map)

remove

public Object remove(Object key)
Specified by:
remove in interface Map<Object,Object>
See Also:
Map.remove(java.lang.Object)

size

public int size()
Specified by:
size in interface Map<Object,Object>
See Also:
Map.size()

values

public Collection<Object> values()
Specified by:
values in interface Map<Object,Object>
See Also:
Map.values()

equals

public boolean equals(Object obj)
Specified by:
equals in interface Map<Object,Object>
Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<Object,Object>
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 1999-2009 The Apache Software Foundation. All Rights Reserved.