[kaffe] How to make Saxon 7.2 work with kaffe
Ito Kazumitsu
ito.kazumitsu@hitachi-cable.co.jp
Thu, 26 Sep 2002 16:05:27 +0900
Tha famous XSLT processor Saxon now requires Java JDK 1.4,
which is not good news to kaffe users.
The following are what I did to make Saxon 7.2 work with kaffe.
1. Add missing packages and classes to kaffe.
(1) Copy java/lang/CharSequence.java from classpath-0.04
(2) Copy java/util/WeakHashMap.java from classpath-0.04 and
apply the following patch
--- java/util/WeakHashMap.java.orig Thu Sep 19 09:34:34 2002
+++ java/util/WeakHashMap.java Thu Sep 19 09:59:22 2002
@@ -86,6 +86,19 @@
*/
public class WeakHashMap extends AbstractMap implements Map
{
+
+ // The following methods were copied from
+ // AbstractMap of classpath because kaffe's does not have ones.
+ static final boolean equals(Object o1, Object o2)
+ {
+ return o1 == null ? o2 == null : o1.equals(o2);
+ }
+ static final int hashCode(Object o)
+ {
+ return o == null ? 0 : o.hashCode();
+ }
+ // end of methods copied from AbstractMap of classpath
+
// WARNING: WeakHashMap is a CORE class in the bootstrap cycle. See the
// comments in vm/reference/java/lang/Runtime for implications of this fact.
(3) Install the package gnu.regexp
(4) Make the package java.util.regex using gnu.regexp
My java.util.regex is attached hereunder. I do not know whether
it works properly. I just want to avoid compile-time errors.
2. Compile the programs under net/sf/saxon. Those programs which
are under net/sf/saxon/fop, net/sf/saxon/jdom and net/sf/saxon/sql
will require other packages, so I excluded them.
Without recompiling, Saxon programs, when run on kaffe, will cause
unexpected errors, which is often the case with class files compiled
by javac of JDK 1.4.
My java.util.regex follows.
$ for f in java/util/regex/*.java; do echo "%%% $f"; cat $f; done
%%% java/util/regex/Matcher.java
package java.util.regex;
import gnu.regexp.RE;
import gnu.regexp.REMatch;
import gnu.regexp.REMatchEnumeration;
public class Matcher
{
private RE re;
private String instr;
private REMatchEnumeration reme;
private REMatch rem;
protected Matcher(String input, RE re)
{
this.instr = input;
this.re = re;
reme = re.getMatchEnumeration(input);
}
public boolean matches() {
return re.isMatch(instr);
}
public boolean find()
{
if (reme.hasMoreMatches()) {
rem = reme.nextMatch();
return true;
}
else {
return false;
}
}
public int start()
{
return rem.getStartIndex();
}
public int start(int sub)
{
return (sub == 0 ? rem.getStartIndex() : rem.getStartIndex(sub));
}
public int end()
{
return rem.getEndIndex();
}
public int end(int sub)
{
return (sub == 0 ? rem.getEndIndex() : rem.getEndIndex(sub));
}
public String group()
{
return instr.substring(start(), end());
}
public String group(int group)
{
return instr.substring(start(group), end(group));
}
public int groupCount()
{
return re.getNumSubs();
}
public String replaceFirst(String replacement)
{
return re.substitute(instr, replacement);
}
public String replaceAll(String replacement)
{
return re.substituteAll(instr, replacement);
}
}
%%% java/util/regex/Pattern.java
package java.util.regex;
import gnu.regexp.RE;
import gnu.regexp.REException;
public class Pattern
{
public static final int UNIX_LINES = 0x01;
public static final int MULTILINE = 0x02;
public static final int DOTALL = 0x04;
private RE re;
private Pattern(String regex, int flags) throws REException
{
int reflags = 0;
if ((flags & UNIX_LINES) != 0) {
/* I do not know what to do */
}
if ((flags & MULTILINE) != 0) {
reflags |= RE.REG_MULTILINE;
}
if ((flags & DOTALL) != 0) {
reflags |= RE.REG_DOT_NEWLINE;
}
re = new RE(regex, reflags);
}
public static Pattern compile(String regex) throws PatternSyntaxException
{
return compile(regex, 0);
}
public static Pattern compile(String regex, int flags) throws PatternSyntaxException
{
try {
return new Pattern(regex, flags);
}
catch (REException e) {
throw new PatternSyntaxException(e.getMessage(), regex, e.getPosition());
}
}
public static boolean matches(String regex, CharSequence input) throws PatternSyntaxException
{
try {
return compile(regex).matcher(input).matches();
}
catch (PatternSyntaxException e) {
throw e;
}
}
public Matcher matcher(CharSequence input)
{
return matcher(input.toString());
}
public Matcher matcher(String input)
{
return new Matcher(input, this.re);
}
public String[] split(CharSequence input, int limit)
{
throw new InternalError("Not implemented yet");
}
}
%%% java/util/regex/PatternSyntaxException.java
package java.util.regex;
public class PatternSyntaxException extends java.lang.IllegalArgumentException
{
public PatternSyntaxException(String desc,
String regex,
int index) {
super(desc);
}
}