Class von “Type Parameter” – Java Generics (gepimpt)

Meine Lösung von gestern funktioniert nicht, wenn die Klassenhierarchy tiefer als Eins ist. Die Methode getGenericSuperclass() liefert eben nur die Superklasse der aktuellen Klasse. Es ist also noch notwendig die Hierarchie nach Dada zu suchen um die Typinformation zu bekommen:

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Parameterized {
    public static void main(String[] args) {
        new SubDada();
        new SubSubDada();
    }
}

abstract class Dada {
    private Class typeOfT;
    public Dada() {
        this.typeOfT = getTypeOfT();
        System.out.println("typeOfT: " + this.typeOfT);
    }
    @SuppressWarnings("unchecked")
    private Class getTypeOfT() {
        ParameterizedType pType = getDadaAsParameterizedType(getClass());
        return (Class) pType.getActualTypeArguments()[0];
    }
    private ParameterizedType getDadaAsParameterizedType(Class clazz) {
        Object gstype = clazz.getGenericSuperclass();
        if (gstype instanceof ParameterizedType) {
            ParameterizedType ptype = (ParameterizedType) gstype;
            Type rawtype = ptype.getRawType();
            if (Dada.class.equals(rawtype)) {
                return ptype;
            }
        }
        return getDadaAsParameterizedType(clazz.getSuperclass());
    }
}

class SubDada extends Dada {
    public SubDada() {
    }
}

class SubSubDada extends SubDada {
    public SubSubDada() {
    }
}

Gentoo, Openoffice und Rechtschreibung (spell checking)

Gestern habe ich etwas geübt, bis ich die Rechtschreibhilfe im Openoffice am laufen hatte. Damit nicht alle so suchen müssen wie ich, hier ein paar Hinweise für die Installation unter Gentoo:

Wer Openoffice selber kompiliert, also nicht das openoffice-bin installiert, muss den USE-Flag odk aktiviert haben. Ich hatte dies vergessen und bei mir ist dann im Openoffice kein Wörterbuch aufgetaucht.

Also habe ich in der Datei /etc/make.conf folgende Ergänzung USE="...nls odk ogg..." vorgenommen.

Danach musste ich dann Openoffice neu kompilieren

emerge openoffice

und habe dann bemerkt, dass es Konflikte beim mergen einiger Dateien gab.

 * This package will overwrite one or more files that may belong to other
 * packages (see list below). You can use a command such as `portageq
 * owners / ` to identify the installed package that owns a
 * file. If portageq reports that only one package owns a file then do
 * NOT file a bug report. A bug report is only useful if it identifies at
 * least two or more packages that are known to install the same file(s).
 * If a collision occurs and you can not explain where the file came from
 * then you should simply ignore the collision since there is not enough
 * information to determine if a real problem exists. Please do NOT file
 * a bug report at http://bugs.gentoo.org unless you report exactly which
 * two packages install the same file(s). Once again, please do NOT file
 * a bug report unless you have completely understood the above message.
 *
 * package app-office/openoffice-2.4.1 NOT merged
 *
 * Detected file collision(s):
 *
 *      /usr/lib/openoffice/share/dict/ooo/th_de_DE.dat
 *      /usr/lib/openoffice/share/dict/ooo/hyph_de_CH.dic
 *      /usr/lib/openoffice/share/dict/ooo/hyph_en_GB.dic
 *      /usr/lib/openoffice/share/dict/ooo/th_de_DE.idx
 *      /usr/lib/openoffice/share/dict/ooo/de_AT.dic
 *      /usr/lib/openoffice/share/dict/ooo/en_CA.aff
 *      /usr/lib/openoffice/share/dict/ooo/en_AU.aff
 *      /usr/lib/openoffice/share/dict/ooo/de_DE.dic
 *      /usr/lib/openoffice/share/dict/ooo/hyph_de_DE.dic
 *      /usr/lib/openoffice/share/dict/ooo/de_CH.dic
 *      /usr/lib/openoffice/share/dict/ooo/en_GB.dic
 *      /usr/lib/openoffice/share/dict/ooo/th_en_US.idx
 *      /usr/lib/openoffice/share/dict/ooo/en_NZ.aff
 *      /usr/lib/openoffice/share/dict/ooo/de_AT.aff
 *      /usr/lib/openoffice/share/dict/ooo/th_en_US.dat
 *      /usr/lib/openoffice/share/dict/ooo/de_DE.aff
 *      /usr/lib/openoffice/share/dict/ooo/en_US.dic
 *      /usr/lib/openoffice/share/dict/ooo/en_AU.dic
 *      /usr/lib/openoffice/share/dict/ooo/en_NZ.dic
 *      /usr/lib/openoffice/share/dict/ooo/en_GB.aff
 *      /usr/lib/openoffice/share/dict/ooo/en_US.aff
 *      /usr/lib/openoffice/share/dict/ooo/de_CH.aff
 *      /usr/lib/openoffice/share/dict/ooo/hyph_en_US.dic
 *      /usr/lib/openoffice/share/dict/ooo/en_CA.dic
 *
 * Searching all installed packages for file collisions...

Also Openoffice nochmals deinstalliert

emerge -C openoffice

und das Verzeichniss mit den Konflikten gelöscht:

rm -rf /usr/lib/openoffice/share

und nochmal installiert (ja, das ganze hat eine Weile gedauert 😦 )
Dann die Wörterbücher installiert:

emerge app-dicts/myspell-en app-dicts/myspell-de app-admin/eselect-oodict

eselect-oodict ist dann zum Auswählen der Wörterbücher für Openoffice mit eselect.

eselect oodict set myspell-de

Und siehe da, die Wörterbücher waren da: