cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <Ralph.Go...@dslextreme.com>
Subject Re: svn commit: r326626 - in /cocoon/blocks: portal-sample/trunk/samples/conf/ portal/trunk/ portal/trunk/java/org/apache/cocoon/portal/ portal/trunk/java/org/apache/cocoon/portal/aspect/impl/ portal/trunk/java/org/apache/cocoon/portal/coplet/ portal/trunk...
Date Wed, 19 Oct 2005 20:35:56 GMT
Carsten Ziegeler wrote:

>Ralph Goers wrote:
>
>  
>
>>I have a concern over the hascode that is used in the
>>DefaultEventConverter.  Although it may not be likely, hash algorithms
>>can return duplicate values so this is not guaranteed to always work.
>>    
>>
>
>Yes, you can configure a mapping on the event converter and use more
>readable keys:
><mapping name="sizing" event-class="o.a.c.p.SOMETHING"/>
>  
>
Well, I see that.  But I just don't see how the urls ever get encoded 
with the name.  See my comments below.

+    public void configure(Configuration config) throws ConfigurationException {
+        Configuration[] mappings = config.getChild("mappings").getChildren("mapping");
+        for( int i=0; i<mappings.length; i++) {
+            final Configuration current = mappings[i];
+            final String key = current.getAttribute("name");
+            final String eventClass = current.getAttribute("event-class");
+            final Constructor c = this.getConstructor(eventClass);
+            final long hash = HashUtil.hash(eventClass);

	The hash of the class name might not be unique.

+            final String hashKey = Long.toString(hash);
+            this.factories.put(hashKey, key);

	The hash key is now associated with the name. However unlikely, this replaced an element
that was already stored with this hashkey.

+            this.factories.put(key, c);
+            
+        }


And in encode...

+            final String factory = event.getClass().getName();
+            final long hash = HashUtil.hash(factory);
             
	We now have a hash of the class name. The hash might not be unique.

+            final String hashKey = Long.toString(hash);

	The hash is now a string.

+            Object o = this.factories.get(hashKey);

	Look up the hashkey and retrieve the object.  If configured this will retrieve the "name"
stored with this hash. There is a small chance this is the wrong name.

+            if ( o == null ) {
+                final Constructor c = this.getConstructor(factory);
+                this.factories.put(hashKey, c);
+                o = c;
             }
-            int index = list.indexOf(event);
-            if ( index == -1 ) {
-                list.add(event);
-                index = list.size() - 1;
+            if ( o instanceof Constructor ) {
+                return hashKey + ':' + data;
             }
-            return String.valueOf(index);




Mime
View raw message