You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by moritz petersen <mo...@mac.com> on 2002/03/17 22:00:09 UTC

Re: question about TranscodingHintKey [possible workaround]

while i do not fully understand the mechanism of RenderingHints and 
RenderingHints.Key, i understand, that it is not possible to get 
the keys by primary key (in this example 10100). obviously, the 
primary keys are stored globally in the virtual machine (the are 
declared static final). batik, on the other hand, gets initialized 
more than once, if there is more than one application that uses 
batik, in the application server's domain.

a possible workaround is to replace the line in the constructors of 
all ...Key classes from

	super(10100); // TranscodingHintKey

to

     super((int) (Math.random() * Integer.MAX_VALUE));

which creates new primary keys every time, batik gets initialized.

this way it is possible to create not unique values, so all ...Key 
classes should be constructed as a singleton, like

while (false) {
	try {
		return new TranscodingHintKey(Math.random() * Integer.MAX_VALUE);
	} catch (Exception e) {
		// the key exists, try again
	}
}

or a unique key generator must be used to create the keys.

maybe there are other workarounds or (better:) *solutions*, that 
require a deeper understanding of the batik architecture.

-moritz.

p.s.: as far as i can say, i think that the RenderingHints / 
RenderingHints.Key implementation is quite bad style: obviously, 
the RenderingHints.Keys are registered using a unique integer, but 
their instances are used as key in the RenderingHints map to 
identify a value. so what are the unique integer keys for? they 
cannot even get called from the outside! even batik doesn't use the 
key '10100' for identifying the TranscodingHintKey. so what?! just 
to use "==" instead of "equals()"?

btw: there is a bug in the javasoft bugparade, which describes 
exactly that problem in the jdk 1.2.2. the state of the bug is 
'closed'!

> i am just beginning to work with batik, and have a couple of 
> problems. one of the problems regards to the TranscodingHintKey... 
> maybe i explain first:
> i am working with apache cocoon 2.0.1. my goal is to define a 
> pipeline, which contains a custom generator (calculating diagram 
> informations), the generated xml is transformed to svg via xsl and 
> then rendered as jpeg (or png whatever), using the svg2jpeg 
> serializer.
> the problem is that i have to restart the server, if i re-deploy 
> the application. it doesn't matter wheter i use tomcat 3.2.4 
> standalone or in combination with jboss 2.2.2.
> the origin of the problem seems to be:
>
> <code>
>
>  final class TranscodingHintKey extends RenderingHints.Key {
>
>       TranscodingHintKey() {
>           super(10100);
>       }
>
> </code>
>
> because i get the error message:
>
> <snip>
>
> java.lang.ExceptionInInitializerError: 
> java.lang.IllegalArgumentException: Instance(10100) of 
> org.apache.batik.ext.awt.TranscodingHintKey already registered
>         at 
> java.awt.RenderingHints$Key.recordIdentity(RenderingHints.java:45)
>         at java.awt.RenderingHints$Key.<init>(RenderingHints.java:64)
>         at 
> org.apache.batik.ext.awt.TranscodingHintKey.<init>(Unknown Source)
>         at 
> org.apache.batik.ext.awt.RenderingHintsKeyExt.<clinit>(Unknown 
> Source)
>
> </snip>
>
> while RenderingHints.Key has only unique instances, the (second) 
> instantiation of the TranscodingHintKey results in the exception.
>
> by the way: this exception does not just occur when re-deploying 
> an application, it gets also thrown, if you access batik from two 
> different applications; example: the cocoon/hello.svg and a custom 
> application myapp/diagram.svg. the second call results in that 
> exception.
>
> while i am not familiar with the java.awt.RenderingHints class, it 
> should be possible to use a singleton like pattern, to return the 
> existing TranscodingHintKey instance, if it exists. i am looking 
> for a solution, but any help would be appreciated!
>
> thank you,
>
> moritz.
>
> p.s.: currently i am using mac os x 10.1.3, jdk 1.3.1 on a 
> powerbook g4. but i know that this problem also happens with a 
> win2k operating system.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org
>
>
--
moritz petersen / +49-177-4196497 / moritzpetersen@mac.com


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org