Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge branch 'enum_type_fix' into 'ibm-trunk'
Enum type fix Find the correct Class in an enum's type hierarchy to use in the call to Enum.valueOf() See merge request !45
- Loading branch information
Showing
4 changed files
with
63 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,43 @@ | ||
package org.apache.yoko.rmi.impl; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
import org.omg.CORBA.portable.IndirectionException; | ||
import org.omg.CORBA.portable.InputStream; | ||
|
||
public final class EnumDescriptor extends ValueDescriptor { | ||
@SuppressWarnings("rawtypes") | ||
private final Class enumType; | ||
|
||
EnumDescriptor(Class<?> type, TypeRepository repository) { | ||
super(type, repository); | ||
enumType = getEnumType(type); | ||
} | ||
|
||
private static Class<?> getEnumType(Class<?> type) { | ||
while (!!!type.isEnum()) { | ||
type = type.getSuperclass(); | ||
} | ||
return type; | ||
} | ||
|
||
@Override | ||
long getSerialVersionUID() { | ||
return 0L; | ||
} | ||
|
||
@Override | ||
public Serializable readValue(InputStream in, Map<Integer, Object> offsetMap, Integer offset) { | ||
try { | ||
in.read_long(); // read in and ignore Enum ordinal | ||
final String name = (String) ((org.omg.CORBA_2_3.portable.InputStream) in).read_value(String.class); | ||
@SuppressWarnings("unchecked") | ||
final Enum<?> value = (Enum<?>) Enum.valueOf(enumType, name); | ||
offsetMap.put(offset, value); | ||
return value; | ||
} catch (IndirectionException ex) { | ||
return (Serializable) offsetMap.get(ex.offset); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters