mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Refactor some RDE import logic to be generic
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=136076610
This commit is contained in:
parent
71d7a382f3
commit
94af94ddff
4 changed files with 51 additions and 50 deletions
|
@ -14,6 +14,8 @@
|
|||
|
||||
package google.registry.util;
|
||||
|
||||
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
|
||||
|
@ -38,12 +40,12 @@ public final class XmlToEnumMapper<T extends Enum<?>> {
|
|||
ImmutableMap.Builder<String, T> mapBuilder = new ImmutableMap.Builder<>();
|
||||
for (T value : enumValues) {
|
||||
try {
|
||||
String xmlName =
|
||||
value
|
||||
.getDeclaringClass()
|
||||
.getField(value.name())
|
||||
.getAnnotation(XmlEnumValue.class)
|
||||
.value();
|
||||
XmlEnumValue xmlAnnotation = value
|
||||
.getDeclaringClass()
|
||||
.getField(value.name())
|
||||
.getAnnotation(XmlEnumValue.class);
|
||||
checkArgumentNotNull(xmlAnnotation, "Cannot map enum value to xml name: " + value);
|
||||
String xmlName = xmlAnnotation.value();
|
||||
mapBuilder = mapBuilder.put(xmlName, value);
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue