Skip to content

Commit

Permalink
Fix cloning of Duration objects
Browse files Browse the repository at this point in the history
Until now, these were cloned by serialization and deserialization
that is slower than a direct approach.
  • Loading branch information
mederly committed May 23, 2019
1 parent f23ccda commit 1d67db9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -38,6 +38,7 @@
import com.evolveum.prism.xml.ns._public.types_3.RawType;
import org.springframework.util.ClassUtils;

import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -109,6 +110,13 @@ public static <T> T clone(T orig) {
if (orig instanceof XMLGregorianCalendar) {
return (T) XmlTypeConverter.createXMLGregorianCalendar((XMLGregorianCalendar) orig);
}
/*
* The following is because of: "Cloning a Serializable (class com.sun.org.apache.xerces.internal.jaxp.datatype.DurationImpl). It could harm performance."
*/
if (orig instanceof Duration) {
//noinspection unchecked
return (T) XmlTypeConverter.createDuration((Duration) orig);
}
if (orig instanceof Cloneable) {
T clone = javaLangClone(orig);
if (clone != null) {
Expand Down
Expand Up @@ -194,6 +194,10 @@ public static Duration createDuration(long durationInMilliSeconds) {
return getDatatypeFactory().newDuration(durationInMilliSeconds);
}

public static Duration createDuration(Duration duration) {
return getDatatypeFactory().newDuration(duration.getSign() >= 0, duration.getYears(), duration.getMonths(), duration.getDays(), duration.getHours(), duration.getMinutes(), duration.getSeconds());
}

public static Duration createDuration(String lexicalRepresentation) {
return lexicalRepresentation != null ? getDatatypeFactory().newDuration(lexicalRepresentation) : null;
}
Expand Down

0 comments on commit 1d67db9

Please sign in to comment.