* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.yang.data.codec.xml;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Verify;
+import static com.google.common.base.Verify.verify;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ImmutableList;
import java.util.Iterator;
import java.util.List;
}
@Override
- public Class<Object> getDataClass() {
+ public Class<Object> getDataType() {
return Object.class;
}
}
SingleType(final Class<T> dataClass, final List<XmlCodec<?>> codecs) {
super(codecs);
- this.dataClass = Preconditions.checkNotNull(dataClass);
+ this.dataClass = requireNonNull(dataClass);
}
@Override
- public Class<T> getDataClass() {
+ public Class<T> getDataType() {
return dataClass;
}
}
private static final Logger LOG = LoggerFactory.getLogger(UnionXmlCodec.class);
- private final List<XmlCodec<?>> codecs;
+ private final ImmutableList<XmlCodec<?>> codecs;
UnionXmlCodec(final List<XmlCodec<?>> codecs) {
this.codecs = ImmutableList.copyOf(codecs);
static UnionXmlCodec<?> create(final UnionTypeDefinition type, final List<XmlCodec<?>> codecs) {
final Iterator<XmlCodec<?>> it = codecs.iterator();
- Verify.verify(it.hasNext(), "Union %s has no subtypes", type);
+ verify(it.hasNext(), "Union %s has no subtypes", type);
- Class<?> dataClass = it.next().getDataClass();
+ Class<?> dataClass = it.next().getDataType();
while (it.hasNext()) {
- final Class<?> next = it.next().getDataClass();
+ final Class<?> next = it.next().getDataType();
if (!dataClass.equals(next)) {
LOG.debug("Type {} has diverse data classes: {} and {}", type, dataClass, next);
return new Diverse(codecs);
}
@Override
- public final T deserializeFromString(final NamespaceContext namespaceContext, final String input) {
+ @SuppressWarnings("checkstyle:illegalCatch")
+ public final T parseValue(final NamespaceContext ctx, final String str) {
for (XmlCodec<?> codec : codecs) {
final Object ret;
try {
- ret = codec.deserializeFromString(namespaceContext, input);
+ ret = codec.parseValue(ctx, str);
} catch (RuntimeException e) {
- LOG.debug("Codec {} did not accept input '{}'", codec, input, e);
+ LOG.debug("Codec {} did not accept input '{}'", codec, str, e);
continue;
}
- return getDataClass().cast(ret);
+ return getDataType().cast(ret);
}
- throw new IllegalArgumentException("Invalid value \"" + input + "\" for union type.");
+ throw new IllegalArgumentException("Invalid value \"" + str + "\" for union type.");
}
@Override
- public void serializeToWriter(final XMLStreamWriter writer, final Object value) throws XMLStreamException {
+ @SuppressWarnings("checkstyle:illegalCatch")
+ public void writeValue(final XMLStreamWriter ctx, final Object value) throws XMLStreamException {
for (XmlCodec<?> codec : codecs) {
- if (!codec.getDataClass().isInstance(value)) {
+ if (!codec.getDataType().isInstance(value)) {
LOG.debug("Codec {} cannot accept input {}, skipping it", codec, value);
continue;
}
@SuppressWarnings("unchecked")
final XmlCodec<Object> objCodec = (XmlCodec<Object>) codec;
try {
- objCodec.serializeToWriter(writer, value);
+ objCodec.writeValue(ctx, value);
return;
} catch (RuntimeException e) {
LOG.debug("Codec {} failed to serialize {}", codec, value, e);