-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Find correct enum type in class hierarchy
- 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
43 changes: 43 additions & 0 deletions
43
yoko-rmi-impl/src/main/java/org/apache/yoko/rmi/impl/EnumDescriptor.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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