mirror of
https://github.com/google/nomulus
synced 2026-01-09 07:33:42 +00: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:
committed by
Ben McIlwain
parent
71d7a382f3
commit
94af94ddff
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user