Announcement Announcement Module
No announcement yet.
IOC with a Map for Resource Management Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • IOC with a Map for Resource Management

    Are there any real world examples (I have seen the documentation on this topic) that show a step by step approach to a newbie that wants to use injection with a Map using the Application context?

    What I am trying to do is have the Application Context populate a Map that will be used to populate all drop downs in the presentation layer. The data is realtively static and I am thinking of it as a resource.

    This post is related to another I made in the web forum on Refence Data Storage/Access. Although it was recommended that I use hibernate, we are thinking that we want a separation of concerns so that this will be treated as more of a service that might be placed on a different server than the Presentation.

  • #2
    Can you define a bit better what you want above and beyond the normal capabilities of the 'map' element supported by the beanfactory/appcontext?


    • #3
      I want a service to populate the Map. I just want to access the map from the Application context.

      I was thinking of calling the service from a constructor and populating a property Map keyValueMap:

      public class RefData {
      	private ArrayList RefDatalist;
      	private Map keyValueMap;
      	public static Logger logger = Logger.getLogger(RefData.class);
      	public RefData()	{
      		RefDataService service = new RefDataService();
      		try {
      			keyValueMap = service.getRefDataMap();
      		catch (Throwable th) {"An Exception has been thrown.");;
      			throw new ApplicationRuntimeException	(th);			
      I then want to store this map, built in the constructor, in the Application Context for the presentation layer to access.
      The service builds the reference data dynamically so I am not sure that the Map element will work but maybe just constructor injection:
      Here is how I build the Map:
      public class GetRefDataService extends HibernateDaoSupport {
      	private String key;
      	private PersistSession persist;
      	public GetRefDataService(PersistSession persist) {
      	public Map buildKeyValueMap() throws Throwable	{
      		RefData refData = new RefData();
      		Map keyValueMap = new HashMap();	
      		ArrayList keys = refData.returnCodeTypeList();
      		for &#40;int i=0; i<keys.size&#40;&#41;;i++&#41;	&#123;
      			String key = keys.get&#40;i&#41;.toString&#40;&#41;;
      			Iterator value = getTextForCode&#40;key&#41;;
      			keyValueMap.put&#40;key, value&#41;;
      		return keyValueMap;
      	public Map execute&#40;&#41; throws Throwable &#123;		
      		Map refDataMap = buildKeyValueMap&#40;&#41;;
      		return refDataMap;		
      	private Iterator getTextForCode&#40;String key&#41; throws Throwable	&#123;
      		List list = null;
      		String refDataType = key;
      //Replace "find" with findByNamedQuery here!**************************************************************
      		list = persist.find&#40;"from REF_DATA in class ReferenceData where REF_DATA_TYPE = '"+ refDataType + "'"&#41;;		
      		return list.iterator&#40;&#41;;
      //Accessors here	


      • #4
        I do not understand what you are trying to achieve here but if you need to expose a result of a bean method call (that is of type Map) in the appcontext, you can do the following
          <bean id="values"
                    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean" singleton="true">
            <property name="targetObject">
              <ref bean="myRefDataService"/>
            <property name="targetMethod">