in yoko-core/src/main/java/org/apache/yoko/orb/OB/CodeSetDatabase.java [142:204]
synchronized public CodeConverterBase getConverter(int to, int from) {
CodeSetInfo toSet = getCodeSetInfo(to);
CodeSetInfo fromSet = getCodeSetInfo(from);
if (toSet != null && fromSet != null) {
if (toSet.max_bytes == 1) {
//
// Optimization: Don't use converter for identical
// narrow codesets
//
if (to == from)
return null;
}
}
CodeConverterBase converter = null;
//
// Conversion possible at all?
//
if (fromSet == null || toSet == null) {
converter = new CodeConverterNone(fromSet, toSet);
} else {
//
// Shortcut for UTF-16 / UCS-2, and UTF-8 / ISOLATIN1
//
if ((toSet.rgy_value == UTF16 || toSet.rgy_value == UCS2)
&& (fromSet.rgy_value == UTF16 || fromSet.rgy_value == UCS2)) {
converter = new CodeConverterSimple(fromSet, toSet);
} else if (((toSet.rgy_value == UTF8 || toSet.rgy_value == ISOLATIN1) && fromSet.rgy_value == UTF8)
|| (toSet.rgy_value == UTF8 && fromSet.rgy_value == ISOLATIN1)) {
converter = new CodeConverterSimple(fromSet, toSet);
} else {
//
// Create new converter and add it to the converter list.
// No conversion to/from ISOLATIN1 and to/from UCS2.
//
CharMapInfo fromMap = null;
CharMapInfo toMap = null;
int fromBase = fromSet.max_bytes == 1 ? ISOLATIN1 : UTF16;
if (fromSet.rgy_value != fromBase)
fromMap = getCharMapInfo(fromSet.rgy_value);
int toBase = toSet.max_bytes == 1 ? ISOLATIN1 : UTF16;
if (toSet.rgy_value != toBase)
toMap = getCharMapInfo(toSet.rgy_value);
if (fromMap != null && toMap != null) {
converter = new CodeConverterBoth(fromSet, toSet, fromMap,
toMap);
} else if (fromMap != null) {
converter = new CodeConverterFrom(fromSet, toSet, fromMap);
} else if (toMap != null) {
converter = new CodeConverterTo(fromSet, toSet, toMap);
} else {
Assert._OB_assert(false);
}
}
}
return converter;
}