Browse Source

Apply "instanceof pattern matching" in remainder of spring-oxm module

See gh-30067
pull/30074/head
Sam Brannen 2 years ago
parent
commit
dafc7a2aab
  1. 26
      spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java

26
spring-oxm/src/main/java/org/springframework/oxm/support/AbstractMarshaller.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -234,17 +234,17 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
*/ */
@Override @Override
public final void marshal(Object graph, Result result) throws IOException, XmlMappingException { public final void marshal(Object graph, Result result) throws IOException, XmlMappingException {
if (result instanceof DOMResult) { if (result instanceof DOMResult domResult) {
marshalDomResult(graph, (DOMResult) result); marshalDomResult(graph, domResult);
} }
else if (StaxUtils.isStaxResult(result)) { else if (StaxUtils.isStaxResult(result)) {
marshalStaxResult(graph, result); marshalStaxResult(graph, result);
} }
else if (result instanceof SAXResult) { else if (result instanceof SAXResult saxResult) {
marshalSaxResult(graph, (SAXResult) result); marshalSaxResult(graph, saxResult);
} }
else if (result instanceof StreamResult) { else if (result instanceof StreamResult streamResult) {
marshalStreamResult(graph, (StreamResult) result); marshalStreamResult(graph, streamResult);
} }
else { else {
throw new IllegalArgumentException("Unknown Result type: " + result.getClass()); throw new IllegalArgumentException("Unknown Result type: " + result.getClass());
@ -353,17 +353,17 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
*/ */
@Override @Override
public final Object unmarshal(Source source) throws IOException, XmlMappingException { public final Object unmarshal(Source source) throws IOException, XmlMappingException {
if (source instanceof DOMSource) { if (source instanceof DOMSource domSource) {
return unmarshalDomSource((DOMSource) source); return unmarshalDomSource(domSource);
} }
else if (StaxUtils.isStaxSource(source)) { else if (StaxUtils.isStaxSource(source)) {
return unmarshalStaxSource(source); return unmarshalStaxSource(source);
} }
else if (source instanceof SAXSource) { else if (source instanceof SAXSource saxSource) {
return unmarshalSaxSource((SAXSource) source); return unmarshalSaxSource(saxSource);
} }
else if (source instanceof StreamSource) { else if (source instanceof StreamSource streamSource) {
return unmarshalStreamSource((StreamSource) source); return unmarshalStreamSource(streamSource);
} }
else { else {
throw new IllegalArgumentException("Unknown Source type: " + source.getClass()); throw new IllegalArgumentException("Unknown Source type: " + source.getClass());

Loading…
Cancel
Save