// Path: src/main/java/com/xebialabs/overcast/Preconditions.java
// public final class Preconditions {
//     private Preconditions() {}
// 
//     public static void checkState(
//             boolean expression,
//             String errorMessageTemplate,
//             Object... errorMessageArgs) {
//         if (!expression) {
//             throw new IllegalStateException(String.format(errorMessageTemplate, errorMessageArgs));
//         }
//     }
// 
//     public static void checkArgument(
//             boolean expression,
//             String errorMessageTemplate,
//             Object... errorMessageArgs) {
//         if (!expression) {
//             throw new IllegalArgumentException(String.format(errorMessageTemplate, errorMessageArgs));
//         }
//     }
// 
//     public static void checkNotNull(Object reference) {
//         if (reference == null) {
//             throw new NullPointerException();
//         }
//     }
// 
//     public static void checkNotNull(
//             Object reference, String errorMessageTemplate, Object... errorMessageArgs) {
//         if (reference == null) {
//             throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));
//         }
//     }
// 
//     public static void checkNotNullOrEmpty(String s) {
//         if (isNullOrEmpty(s)) {
//             throw new NullPointerException();
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/xebialabs/overcast/support/libvirt/JDomUtil.java
// public static String getElementText(Element parent, String localName, Namespace ns) {
//     if (parent == null) {
//         throw new IllegalArgumentException("parent element not found");
//     }
//     Element child = parent.getChild(localName, ns);
//     if (child == null) {
//         throw new IllegalArgumentException(String.format("child element '%s' not found", localName));
//     }
//     return child.getText();
// }


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import com.xebialabs.overcast.Preconditions;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import static com.xebialabs.overcast.support.libvirt.JDomUtil.getElementText;
        Element metadata = new Element(METADATA);
        Element ocmetadata = new Element(OVERCAST_METADATA, METADATA_NS_V1);
        metadata.addContent(ocmetadata);

        ocmetadata.addContent(new Element(PARENT_DOMAIN, METADATA_NS_V1).setText(parentDomain));
        ocmetadata.addContent(new Element(CREATION_TIME, METADATA_NS_V1).setText(sdf.format(creationTime)));

        return metadata;
    }

    private static Element getMetadataElement(Document domainXml) {
        return domainXml.getRootElement().getChild(METADATA);
    }

    public static void updateProvisioningMetadata(Document domainXml, String baseDomainName, String provisionCmd, String expirationTag, Date creationTime) {
        checkArgument(baseDomainName, "baseDomainName");
        checkArgument(provisionCmd, "provisionCmd");
        checkArgument(expirationTag, "expirationTag");
        Preconditions.checkNotNull(creationTime, "creationTime must not be null");

        Element element = getMetadataElement(domainXml);
        if (element != null) {
            domainXml.getRootElement().removeContent(element);
        }
        Element metadata = createProvisioningMetadata(baseDomainName, provisionCmd, expirationTag, creationTime);
        domainXml.getRootElement().addContent(metadata);
    }

    public static void updateCloneMetadata(Document domainXml, String baseDomainName, Date creationTime) {
        checkArgument(baseDomainName, "baseDomainName");
// Path: src/main/java/com/xebialabs/overcast/Preconditions.java
// public final class Preconditions {
//     private Preconditions() {}
// 
//     public static void checkState(
//             boolean expression,
//             String errorMessageTemplate,
//             Object... errorMessageArgs) {
//         if (!expression) {
//             throw new IllegalStateException(String.format(errorMessageTemplate, errorMessageArgs));
//         }
//     }
// 
//     public static void checkArgument(
//             boolean expression,
//             String errorMessageTemplate,
//             Object... errorMessageArgs) {
//         if (!expression) {
//             throw new IllegalArgumentException(String.format(errorMessageTemplate, errorMessageArgs));
//         }
//     }
// 
//     public static void checkNotNull(Object reference) {
//         if (reference == null) {
//             throw new NullPointerException();
//         }
//     }
// 
//     public static void checkNotNull(
//             Object reference, String errorMessageTemplate, Object... errorMessageArgs) {
//         if (reference == null) {
//             throw new NullPointerException(String.format(errorMessageTemplate, errorMessageArgs));
//         }
//     }
// 
//     public static void checkNotNullOrEmpty(String s) {
//         if (isNullOrEmpty(s)) {
//             throw new NullPointerException();
//         }
//     }
// 
// }
// 
// Path: src/main/java/com/xebialabs/overcast/support/libvirt/JDomUtil.java
// public static String getElementText(Element parent, String localName, Namespace ns) {
//     if (parent == null) {
//         throw new IllegalArgumentException("parent element not found");
//     }
//     Element child = parent.getChild(localName, ns);
//     if (child == null) {
//         throw new IllegalArgumentException(String.format("child element '%s' not found", localName));
//     }
//     return child.getText();
// }


// Path: src/main/java/com/xebialabs/overcast/support/libvirt/Metadata.java
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import com.xebialabs.overcast.Preconditions;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.Namespace;
import static com.xebialabs.overcast.support.libvirt.JDomUtil.getElementText;

        Element metadata = new Element(METADATA);
        Element ocmetadata = new Element(OVERCAST_METADATA, METADATA_NS_V1);
        metadata.addContent(ocmetadata);

        ocmetadata.addContent(new Element(PARENT_DOMAIN, METADATA_NS_V1).setText(parentDomain));
        ocmetadata.addContent(new Element(CREATION_TIME, METADATA_NS_V1).setText(sdf.format(creationTime)));

        return metadata;
    }

    private static Element getMetadataElement(Document domainXml) {
        return domainXml.getRootElement().getChild(METADATA);
    }

    public static void updateProvisioningMetadata(Document domainXml, String baseDomainName, String provisionCmd, String expirationTag, Date creationTime) {
        checkArgument(baseDomainName, "baseDomainName");
        checkArgument(provisionCmd, "provisionCmd");
        checkArgument(expirationTag, "expirationTag");
        Preconditions.checkNotNull(creationTime, "creationTime must not be null");

        Element element = getMetadataElement(domainXml);
        if (element != null) {
            domainXml.getRootElement().removeContent(element);
        }
        Element metadata = createProvisioningMetadata(baseDomainName, provisionCmd, expirationTag, creationTime);
        domainXml.getRootElement().addContent(metadata);
    }

    public static void updateCloneMetadata(Document domainXml, String baseDomainName, Date creationTime) {
        checkArgument(baseDomainName, "baseDomainName");
        Preconditions.checkNotNull(creationTime, "creationTime must not be null");