You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jacob Hookom <ho...@uwec.edu> on 2003/01/22 20:42:52 UTC

[OT] [Digester] Mapping Children to Parent Object

This is a best-practices question.  I'm nearing the completion of a caching
framework and I'm now writing the configuration package with Digester.

<!-- simplified version -->
<cache-config>
	<cache name="CACHE_A">
		<module type="com.enverio.cache.module.SoftCacheModule" />
		<module type="com.enverio.cache.module.DiskCacheModule"
			  rootPath="/WEB-INF/cache"
			  extension="cache" />
	</cache>
	<cache name="CACHE_B">
		<module type="com.enverio.cache.module.DatabaseCacheModule"
			  driver="someDriver"
			  url="something"
			  username="temp"
			  password="temp" />
	</cache>
</cache-config>

Cache-Config nodes create a CacheController which is a wrapper for a Map of
Caches.  I would like to avoid adding a "name" property to my Cache object,
but still have that value passed to the parent (CacheController) for mapping
purposes.

Does anyone have any pointers as to how to best accomplish this without
modifying my framework code just for Digester?

Best Regards,
Jacob Hookom


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


AW: [OT] [Digester] Mapping Children to Parent Object

Posted by Jacob Hookom <ho...@uwec.edu>.
I was unable to get the CallMethodRule to accomplish the mapping properly
(probably my own fault), but I instead wrote a very simple ObjectMapRule
that will handle this common mapping requirement.

<parent type="java.util.HashMap">
     <child name="A" type="some object"/>
     <child name="B" type="some object"/>
</parent>

// Source
digester.addRule("parent/child", new ObjectMapRule("put", "name"));

// results in
assertNotNull(map.get("A"));
assertNotNull(map.get("B"));

The source code is attached for whoever wants to use it to simplify things a
bit in your configuration files (useful debug and error statements are
already written for use with digester's logger).

Best Regards,
Jacob Hookom

-----Original Message-----
From: Jacob Hookom [mailto:hookomjj@uwec.edu] 
Sent: Wednesday, January 22, 2003 1:43 PM
To: Struts Users Mailing List
Subject: [OT] [Digester] Mapping Children to Parent Object

This is a best-practices question.  I'm nearing the completion of a caching
framework and I'm now writing the configuration package with Digester.

<!-- simplified version -->
<cache-config>
	<cache name="CACHE_A">
		<module type="com.enverio.cache.module.SoftCacheModule" />
		<module type="com.enverio.cache.module.DiskCacheModule"
			  rootPath="/WEB-INF/cache"
			  extension="cache" />
	</cache>
	<cache name="CACHE_B">
		<module type="com.enverio.cache.module.DatabaseCacheModule"
			  driver="someDriver"
			  url="something"
			  username="temp"
			  password="temp" />
	</cache>
</cache-config>

Cache-Config nodes create a CacheController which is a wrapper for a Map of
Caches.  I would like to avoid adding a "name" property to my Cache object,
but still have that value passed to the parent (CacheController) for mapping
purposes.

Does anyone have any pointers as to how to best accomplish this without
modifying my framework code just for Digester?

Best Regards,
Jacob Hookom


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>