|
Description
|
java version "1.3.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_01)
Java HotSpot(TM) Client VM (build 1.3.1_01, mixed mode)
javax.media.jai.JAI.getBuildVersion() works okay in a standalone program,
returning a result like this:
jai-1_1_1 Thu Sep 27 00:15:28 PDT 2001
But it fails to return useful information in an applet within a browser,
in which environment it says:
JAI Build version unavailable.
We suspect that this is because the JAI tries to read some local files
to obtain the build version, which action violates the security model.
This behavior is, ah, less than ideal. It means we cannot unambiguously
determine what version of the software our end-users are running, which
of course will probably lead to field support problems.
The information yielded by this routine should be hardcoded somewhere in
the .jar files of the extension, so an applet can access the build version.
Here is a sample applet that demonstrates the problem.
import java.awt.*;
import java.applet.*;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class VersionAppletJAI extends Applet{
private boolean fontsSet = false;
private String jvmMessage = " ", jaiMessage = " ";
private Font f = new Font ("HELVETICA", Font.PLAIN, 12);
private FontMetrics fm;
private int dy, fHeight, x1, x2, y;
public void init(){
String java_version = java.lang.System.getProperty("java.version");
try{
Class jaiClass = Class.forName("javax.media.jai.JAI");
Object jaiInstance = jaiClass.newInstance();
Method method = jaiClass.getMethod("getBuildVersion", null);
String jaiVersion = javax.media.jai.JAI.getBuildVersion();
// The problem is right here. An applet always gets the
// following result, instead of useful information.
if (jaiVersion.equals("JAI Build version unavailable.")){
jaiMessage = "JAI 1.1 or higher is available with this JVM, but the exact version cannot be determined.";
}else{
jaiMessage = "You have " + jaiVersion + " associated with this JVM.";
}
}catch(ClassNotFoundException ex){
jaiMessage = "You have no JAI associated with this JVM.";
}catch(NoSuchMethodException ex){
jaiMessage = "You have no JAI 1.1.1 associated with this JVM.";
}catch(InstantiationException ex){
jaiMessage = "JAI will not work with Java " + java_version + ".";
}catch(IllegalAccessException ex){
}catch(NoClassDefFoundError ex){
jaiMessage = "You have no JAI associated with this JVM.";
}
String java_vendor = java.lang.System.getProperty("java.vendor");
String JVM_Origin = getParameter ("JVM_Origin");
jvmMessage = JVM_Origin + " is Java " + java_version + " from " + java_vendor;
}
public void restart(){
repaint();
}
public void paint(Graphics g){
g.setFont (f);
Insets in = getInsets();
Dimension d = getSize();
if (!fontsSet){
fm = g.getFontMetrics(f);
dy = (fm.getAscent() - fm.getDescent()) / 2;
fHeight = fm.getHeight();
fontsSet = true;
int w1 = fm.stringWidth(jvmMessage);
int w2 = fm.stringWidth(jaiMessage);
int applet_width = d.width - in.right - in.left;
int applet_height = d.height - in.bottom - in.top;
x1 = (applet_width - w1)/2;
x2 = (applet_width - w2)/2;
y = applet_height/2;
}
Rectangle clip = g.getClipBounds();
g.setColor(new Color(240, 255, 240));
g.fillRect(clip.x, clip.y, clip.width, clip.height);
g.setColor(Color.black);
g.drawString (jvmMessage, x1, y + dy - fHeight/2);
g.drawString (jaiMessage, x2, y + dy + fHeight/2);
}
}
(Review ID: 133603)
======================================================================
Posted Date : 2005-11-23 22:51:33.0
|