// Path: src/main/java/eu/delving/x3ml/X3MLEngine.java
// public interface Output {
// 
//     void write(PrintStream printStream, String rdfFormat);
// 
//     void writeXML(PrintStream printStream);
// 
//     Model getModel();
//         
//     String[] toStringArray();
// 
// }
// 
// Path: src/main/java/eu/delving/x3ml/X3MLEngine.java
// public static X3MLException exception(String message) {
//     return new X3MLException(message);
// }
// 
// Path: src/main/java/eu/delving/x3ml/engine/X3ML.java
// @XStreamAlias("type")
// @XStreamConverter(value = ToAttributedValueConverter.class, strings = {"tag"})
// public static class TypeElement extends Visible {
// 
//     public String tag;
// 
//     @XStreamOmitField
//     public String namespaceUri;
// 
//     public TypeElement() {
//     }
// 
//     public TypeElement(String tag, String namespaceUri) {
//         this.tag = tag;
//         this.namespaceUri = namespaceUri;
//     }
// 
//     public String getPrefix() {
//         int colon = tag.indexOf(':');
//         if (colon < 0) {
//             throw exception("Unqualified tag " + tag);
//         }
//         return tag.substring(0, colon);
//     }
// 
//     public String getLocalName() {
//         int colon = tag.indexOf(':');
//         if (colon < 0) {
//             throw exception("Unqualified tag " + tag);
//         }
//         return tag.substring(colon + 1);
//     }
// }


import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import javax.xml.namespace.NamespaceContext;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static eu.delving.x3ml.X3MLEngine.Output;
import static eu.delving.x3ml.X3MLEngine.exception;
import static eu.delving.x3ml.engine.X3ML.TypeElement;

//===========================================================================
//    Copyright 2014 Delving B.V.
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
//===========================================================================
package eu.delving.x3ml.engine;




/**
 * The output sent to a Jena graph model.
 *
 * @author Gerald de Jong <gerald@delving.eu>
 */
public class ModelOutput implements Output {

    private final Model model;
    private final NamespaceContext namespaceContext;

    public ModelOutput(Model model, NamespaceContext namespaceContext) {
        this.model = model;
        this.namespaceContext = namespaceContext;
    }

    public Model getModel() {
        return model;
    }

    public Resource createTypedResource(String uriString, TypeElement typeElement) {
        if (typeElement == null) {
            throw exception("Missing qualified name");
        }
        String typeUri = namespaceContext.getNamespaceURI(typeElement.getPrefix());
        return model.createResource(uriString, model.createResource(typeUri + typeElement.getLocalName()));
    }

    public Property createProperty(TypeElement typeElement) {
        if (typeElement == null) {
            throw exception("Missing qualified name");
        }
        String propertyNamespace = namespaceContext.getNamespaceURI(typeElement.getPrefix());
        return model.createProperty(propertyNamespace, typeElement.getLocalName());
    }

    public Property createProperty(X3ML.Relationship relationship) {
        if (relationship == null) {

// Path: src/main/java/eu/delving/x3ml/X3MLEngine.java
// public interface Output {
// 
//     void write(PrintStream printStream, String rdfFormat);
// 
//     void writeXML(PrintStream printStream);
// 
//     Model getModel();
//         
//     String[] toStringArray();
// 
// }
// 
// Path: src/main/java/eu/delving/x3ml/X3MLEngine.java
// public static X3MLException exception(String message) {
//     return new X3MLException(message);
// }
// 
// Path: src/main/java/eu/delving/x3ml/engine/X3ML.java
// @XStreamAlias("type")
// @XStreamConverter(value = ToAttributedValueConverter.class, strings = {"tag"})
// public static class TypeElement extends Visible {
// 
//     public String tag;
// 
//     @XStreamOmitField
//     public String namespaceUri;
// 
//     public TypeElement() {
//     }
// 
//     public TypeElement(String tag, String namespaceUri) {
//         this.tag = tag;
//         this.namespaceUri = namespaceUri;
//     }
// 
//     public String getPrefix() {
//         int colon = tag.indexOf(':');
//         if (colon < 0) {
//             throw exception("Unqualified tag " + tag);
//         }
//         return tag.substring(0, colon);
//     }
// 
//     public String getLocalName() {
//         int colon = tag.indexOf(':');
//         if (colon < 0) {
//             throw exception("Unqualified tag " + tag);
//         }
//         return tag.substring(colon + 1);
//     }
// }


// Path: src/main/java/eu/delving/x3ml/engine/ModelOutput.java
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import javax.xml.namespace.NamespaceContext;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static eu.delving.x3ml.X3MLEngine.Output;
import static eu.delving.x3ml.X3MLEngine.exception;
import static eu.delving.x3ml.engine.X3ML.TypeElement;

//===========================================================================
//    Copyright 2014 Delving B.V.
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
//===========================================================================
package eu.delving.x3ml.engine;




/**
 * The output sent to a Jena graph model.
 *
 * @author Gerald de Jong <gerald@delving.eu>
 */
public class ModelOutput implements Output {

    private final Model model;
    private final NamespaceContext namespaceContext;

    public ModelOutput(Model model, NamespaceContext namespaceContext) {
        this.model = model;
        this.namespaceContext = namespaceContext;
    }

    public Model getModel() {
        return model;
    }

    public Resource createTypedResource(String uriString, TypeElement typeElement) {
        if (typeElement == null) {
            throw exception("Missing qualified name");
        }
        String typeUri = namespaceContext.getNamespaceURI(typeElement.getPrefix());
        return model.createResource(uriString, model.createResource(typeUri + typeElement.getLocalName()));
    }

    public Property createProperty(TypeElement typeElement) {
        if (typeElement == null) {
            throw exception("Missing qualified name");
        }
        String propertyNamespace = namespaceContext.getNamespaceURI(typeElement.getPrefix());
        return model.createProperty(propertyNamespace, typeElement.getLocalName());
    }

    public Property createProperty(X3ML.Relationship relationship) {
        if (relationship == null) {

            throw exception("Missing qualified name");
