// Path: src/main/java/com/epimorphics/registry/vocab/Version.java
// public class Version {
//     /** <p>The ontology model that holds the vocabulary terms</p> */
//     private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
//     
//     /** <p>The namespace of the vocabulary as a string</p> */
//     public static final String NS = "http://purl.org/linked-data/version#";
//     
//     /** <p>The namespace of the vocabulary as a string</p>
//      *  @see #NS */
//     public static String getURI() {return NS;}
//     
//     /** <p>The namespace of the vocabulary as a resource</p> */
//     public static final Resource NAMESPACE = m_model.createResource( NS );
//     
//     /** <p>The ontology's owl:versionInfo as a string</p> */
//     public static final String VERSION_INFO = "0.1";
//     
//     /** <p>currentVersion relates an enduring resource to its current version</p> */
//     public static final ObjectProperty currentVersion = m_model.createObjectProperty( "http://purl.org/linked-data/version#currentVersion" );
//     
//     /** <p>interval relates a thing version to an interval during which the version was 
//      *  valid.</p>
//      */
//     public static final ObjectProperty interval = m_model.createObjectProperty( "http://purl.org/linked-data/version#interval" );
//     
//     /** <p>Indicates a property which does not change across versions of a VersionedThing</p> */
//     public static final ObjectProperty rigidProperty = m_model.createObjectProperty( "http://purl.org/linked-data/version#rigidProperty" );
//     
//     /** <p>A version of a versioned thing.</p> */
//     public static final OntClass Version = m_model.createClass( "http://purl.org/linked-data/version#Version" );
//     
//     /** <p>The class of things that can have multiple versions.</p> */
//     public static final OntClass VersionedThing = m_model.createClass( "http://purl.org/linked-data/version#VersionedThing" );
//     
// }


import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import com.epimorphics.rdfutil.RDFUtil;
import com.epimorphics.registry.vocab.Version;
import com.epimorphics.vocabs.Time;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.util.ResourceUtils;
import com.hp.hpl.jena.vocabulary.DCTerms;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;
            } else {
                ver.addProperty(p, value);
            }
        }

        ver.addLiteral(OWL.versionInfo, vNum)
           .addProperty(DCTerms.isVersionOf, root);
        newRoot.addProperty(Version.currentVersion, ver);
        makeInterval(ver, timemark, null);
        if (currentVersion != null) {
            ver.addProperty(DCTerms.replaces, currentVersion);
            makeInterval(currentVersion, null, timemark);
        }
        return ver;
    }

    private static Resource makeTimePoint(Model vModel, Calendar timemark) {
        Literal timemarkL = vModel.createTypedLiteral(timemark);
        return vModel.createResource().addProperty(Time.inXSDDateTime, timemarkL);
    }

    private static Resource makeInterval(Resource version, Calendar start, Calendar end) {
        Model m = version.getModel();
        Resource interval = m.createResource( version.getURI() + "#interval" );
        if (start != null) {
            interval.addProperty(Time.hasBeginning, makeTimePoint(m, start));
        }
        if (end != null) {
            interval.addProperty(Time.hasEnd, makeTimePoint(m, end));
        }
// Path: src/main/java/com/epimorphics/registry/vocab/Version.java
// public class Version {
//     /** <p>The ontology model that holds the vocabulary terms</p> */
//     private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
//     
//     /** <p>The namespace of the vocabulary as a string</p> */
//     public static final String NS = "http://purl.org/linked-data/version#";
//     
//     /** <p>The namespace of the vocabulary as a string</p>
//      *  @see #NS */
//     public static String getURI() {return NS;}
//     
//     /** <p>The namespace of the vocabulary as a resource</p> */
//     public static final Resource NAMESPACE = m_model.createResource( NS );
//     
//     /** <p>The ontology's owl:versionInfo as a string</p> */
//     public static final String VERSION_INFO = "0.1";
//     
//     /** <p>currentVersion relates an enduring resource to its current version</p> */
//     public static final ObjectProperty currentVersion = m_model.createObjectProperty( "http://purl.org/linked-data/version#currentVersion" );
//     
//     /** <p>interval relates a thing version to an interval during which the version was 
//      *  valid.</p>
//      */
//     public static final ObjectProperty interval = m_model.createObjectProperty( "http://purl.org/linked-data/version#interval" );
//     
//     /** <p>Indicates a property which does not change across versions of a VersionedThing</p> */
//     public static final ObjectProperty rigidProperty = m_model.createObjectProperty( "http://purl.org/linked-data/version#rigidProperty" );
//     
//     /** <p>A version of a versioned thing.</p> */
//     public static final OntClass Version = m_model.createClass( "http://purl.org/linked-data/version#Version" );
//     
//     /** <p>The class of things that can have multiple versions.</p> */
//     public static final OntClass VersionedThing = m_model.createClass( "http://purl.org/linked-data/version#VersionedThing" );
//     
// }


// Path: src/main/java/com/epimorphics/registry/util/VersionUtil.java
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import com.epimorphics.rdfutil.RDFUtil;
import com.epimorphics.registry.vocab.Version;
import com.epimorphics.vocabs.Time;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.util.ResourceUtils;
import com.hp.hpl.jena.vocabulary.DCTerms;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF;

            } else {
                ver.addProperty(p, value);
            }
        }

        ver.addLiteral(OWL.versionInfo, vNum)
           .addProperty(DCTerms.isVersionOf, root);
        newRoot.addProperty(Version.currentVersion, ver);
        makeInterval(ver, timemark, null);
        if (currentVersion != null) {
            ver.addProperty(DCTerms.replaces, currentVersion);
            makeInterval(currentVersion, null, timemark);
        }
        return ver;
    }

    private static Resource makeTimePoint(Model vModel, Calendar timemark) {
        Literal timemarkL = vModel.createTypedLiteral(timemark);
        return vModel.createResource().addProperty(Time.inXSDDateTime, timemarkL);
    }

    private static Resource makeInterval(Resource version, Calendar start, Calendar end) {
        Model m = version.getModel();
        Resource interval = m.createResource( version.getURI() + "#interval" );
        if (start != null) {
            interval.addProperty(Time.hasBeginning, makeTimePoint(m, start));
        }
        if (end != null) {
            interval.addProperty(Time.hasEnd, makeTimePoint(m, end));
        }
        version.addProperty(Version.interval, interval);