Search in sources :

Example 1 with UpdateWriter

use of org.apache.jena.sparql.modify.request.UpdateWriter in project jena by apache.

the class SerializerRegistry method init.

private static synchronized void init() {
    SerializerRegistry reg = new SerializerRegistry();
    // Register standard serializers
    QuerySerializerFactory arqQuerySerializerFactory = new QuerySerializerFactory() {

        @Override
        public QueryVisitor create(Syntax syntax, Prologue prologue, IndentedWriter writer) {
            // For the query pattern
            SerializationContext cxt1 = new SerializationContext(prologue, new NodeToLabelMapBNode("b", false));
            // For the construct pattern
            SerializationContext cxt2 = new SerializationContext(prologue, new NodeToLabelMapBNode("c", false));
            return new QuerySerializer(writer, new FormatterElement(writer, cxt1), new FmtExprSPARQL(writer, cxt1), new FmtTemplate(writer, cxt2));
        }

        @Override
        public QueryVisitor create(Syntax syntax, SerializationContext context, IndentedWriter writer) {
            return new QuerySerializer(writer, new FormatterElement(writer, context), new FmtExprSPARQL(writer, context), new FmtTemplate(writer, context));
        }

        @Override
        public boolean accept(Syntax syntax) {
            // and SPARQL 1.1 can be serialized by the same serializer
            return Syntax.syntaxARQ.equals(syntax) || Syntax.syntaxSPARQL_10.equals(syntax) || Syntax.syntaxSPARQL_11.equals(syntax);
        }
    };
    reg.addQuerySerializer(Syntax.syntaxARQ, arqQuerySerializerFactory);
    reg.addQuerySerializer(Syntax.syntaxSPARQL_10, arqQuerySerializerFactory);
    reg.addQuerySerializer(Syntax.syntaxSPARQL_11, arqQuerySerializerFactory);
    UpdateSerializerFactory arqUpdateSerializerFactory = new UpdateSerializerFactory() {

        @Override
        public UpdateSerializer create(Syntax syntax, Prologue prologue, IndentedWriter writer) {
            if (!prologue.explicitlySetBaseURI())
                prologue = new Prologue(prologue.getPrefixMapping(), (IRIResolver) null);
            SerializationContext context = new SerializationContext(prologue);
            return new UpdateWriter(writer, context);
        }

        @Override
        public boolean accept(Syntax syntax) {
            // and SPARQL 1.1 can be serialized by the same serializer
            return Syntax.syntaxARQ.equals(syntax) || Syntax.syntaxSPARQL_10.equals(syntax) || Syntax.syntaxSPARQL_11.equals(syntax);
        }
    };
    reg.addUpdateSerializer(Syntax.syntaxARQ, arqUpdateSerializerFactory);
    reg.addUpdateSerializer(Syntax.syntaxSPARQL_10, arqUpdateSerializerFactory);
    reg.addUpdateSerializer(Syntax.syntaxSPARQL_11, arqUpdateSerializerFactory);
    registry = reg;
}
Also used : NodeToLabelMapBNode(org.apache.jena.sparql.util.NodeToLabelMapBNode) UpdateWriter(org.apache.jena.sparql.modify.request.UpdateWriter) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) Prologue(org.apache.jena.sparql.core.Prologue) Syntax(org.apache.jena.query.Syntax)

Aggregations

IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)1 Syntax (org.apache.jena.query.Syntax)1 Prologue (org.apache.jena.sparql.core.Prologue)1 UpdateWriter (org.apache.jena.sparql.modify.request.UpdateWriter)1 NodeToLabelMapBNode (org.apache.jena.sparql.util.NodeToLabelMapBNode)1