You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2015/04/23 21:56:34 UTC
[18/51] [partial] jena git commit: Rename com.hp.hpl.jena.* as
org.apache.jena.*
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeConst.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeConst.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeConst.java
deleted file mode 100644
index 52e7f0d..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeConst.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.graph;
-
-import com.hp.hpl.jena.datatypes.RDFDatatype ;
-import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.NodeFactory ;
-import com.hp.hpl.jena.vocabulary.OWL ;
-import com.hp.hpl.jena.vocabulary.RDF ;
-
-/** Some node constants */
-public class NodeConst
-{
- public static final Node nodeTrue = NodeFactory.createLiteral("true", XSDDatatype.XSDboolean) ;
- public static final Node nodeFalse = NodeFactory.createLiteral("false",XSDDatatype.XSDboolean) ;
- public static final Node nodeZero = NodeFactory.createLiteral("0", XSDDatatype.XSDinteger) ;
- public static final Node nodeOne = NodeFactory.createLiteral("1", XSDDatatype.XSDinteger) ;
- public static final Node nodeTwo = NodeFactory.createLiteral("2", XSDDatatype.XSDinteger) ;
- public static final Node nodeMinusOne = NodeFactory.createLiteral("-1", XSDDatatype.XSDinteger) ;
- public static final Node emptyString = NodeFactory.createLiteral("") ;
-
- public static final Node nodeRDFType = RDF.Nodes.type ;
- public static final Node nodeFirst = RDF.Nodes.first ;
- public static final Node nodeRest = RDF.Nodes.rest ;
- public static final Node nodeNil = RDF.Nodes.nil ;
- public static final Node nodeANY = Node.ANY ;
-
- public static final Node nodeOwlSameAs = OWL.sameAs.asNode() ;
- public static final Node rdfLangString = RDF.Nodes.langString ;
- public static final RDFDatatype dtLangString = RDF.dtLangString ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransform.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransform.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransform.java
deleted file mode 100644
index 942989e..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransform.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.graph;
-
-import org.apache.jena.atlas.iterator.Transform ;
-
-import com.hp.hpl.jena.graph.Node ;
-
-/** Convert nodes to nodes - Vars may need to be translated into Vars. */
-public interface NodeTransform extends Transform<Node, Node>
-{
- @Override
- public Node convert(Node node) ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java
deleted file mode 100644
index 4149955..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformLib.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.graph;
-
-import java.util.ArrayList ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import static org.apache.jena.atlas.lib.Lib.equal ;
-
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.query.SortCondition ;
-import com.hp.hpl.jena.sparql.algebra.Op ;
-import com.hp.hpl.jena.sparql.algebra.Table ;
-import com.hp.hpl.jena.sparql.algebra.Transform ;
-import com.hp.hpl.jena.sparql.algebra.Transformer ;
-import com.hp.hpl.jena.sparql.algebra.table.TableData ;
-import com.hp.hpl.jena.sparql.core.BasicPattern ;
-import com.hp.hpl.jena.sparql.core.Quad ;
-import com.hp.hpl.jena.sparql.core.QuadPattern ;
-import com.hp.hpl.jena.sparql.core.Var ;
-import com.hp.hpl.jena.sparql.core.VarExprList ;
-import com.hp.hpl.jena.sparql.engine.binding.Binding ;
-import com.hp.hpl.jena.sparql.engine.binding.BindingFactory ;
-import com.hp.hpl.jena.sparql.engine.binding.BindingMap ;
-import com.hp.hpl.jena.sparql.expr.Expr ;
-import com.hp.hpl.jena.sparql.expr.ExprList ;
-
-public class NodeTransformLib
-{
- /** Do a node->node conversion of an Op - return original BGP for "no change" */
- public static Op transform(NodeTransform nodeTransform, Op op)
- {
- Transform opTransform = new NodeTransformOp(nodeTransform) ;
- return Transformer.transform(opTransform, null, op) ; // No expr transform - we do it ourselves.
- }
-
- /** Do a node->node conversion of a BGP - return original BGP for "no change" */
- public static BasicPattern transform(NodeTransform nodeTransform, BasicPattern pattern)
- {
- BasicPattern bgp2 = new BasicPattern() ;
- boolean changed = false ;
- for ( Triple triple : pattern )
- {
- Triple t2 = transform(nodeTransform, triple) ;
- bgp2.add(t2) ;
- if ( t2 != triple )
- changed = true ;
- }
- if ( ! changed )
- return pattern ;
- return bgp2 ;
- }
-
- /** Do a node->node conversion of a QuadPattern - return original QuadPattern for "no change" */
- public static QuadPattern transform(NodeTransform nodeTransform, QuadPattern pattern)
- {
- QuadPattern qp2 = new QuadPattern() ;
- boolean changed = false ;
- for ( Quad quad : pattern )
- {
- Quad q2 = transform(nodeTransform, quad) ;
- qp2.add(q2) ;
- if ( q2 != quad )
- changed = true ;
- }
- if ( ! changed )
- return pattern ;
- return qp2 ;
- }
-
- /** Do a node->node conversion of a Triple - return original Triple for "no change" */
- public static Triple transform(NodeTransform nodeTransform, Triple triple)
- {
- boolean change = false ;
- Node s = triple.getSubject() ;
- Node p = triple.getPredicate() ;
- Node o = triple.getObject() ;
-
- Node s1 = nodeTransform.convert(s) ;
- if ( s1 != s ) { change = true ; s = s1 ; }
- Node p1 = nodeTransform.convert(p) ;
- if ( p1 != p ) { change = true ; p = p1 ; }
- Node o1 = nodeTransform.convert(o) ;
- if ( o1 != o ) { change = true ; o = o1 ; }
-
- if ( ! change )
- return triple ;
- return new Triple(s,p,o) ;
- }
-
- /** Do a node->node conversion of a Quad - return original Quad for "no change" */
- public static Quad transform(NodeTransform nodeTransform, Quad quad)
- {
- boolean change = false ;
- Node s = quad.getSubject() ;
- Node p = quad.getPredicate() ;
- Node o = quad.getObject() ;
- Node g = quad.getGraph() ;
-
- Node g1 = nodeTransform.convert(g) ;
- if ( g1 != g ) { change = true ; g = g1 ; }
- Node s1 = nodeTransform.convert(s) ;
- if ( s1 != s ) { change = true ; s = s1 ; }
- Node p1 = nodeTransform.convert(p) ;
- if ( p1 != p ) { change = true ; p = p1 ; }
- Node o1 = nodeTransform.convert(o) ;
- if ( o1 != o ) { change = true ; o = o1 ; }
-
- if ( ! change )
- return quad ;
- return new Quad(g,s,p,o) ;
- }
-
- public static Table transform(Table table, NodeTransform transform) {
- // Non-streaming rewrite
- List<Var> vars = transformVars(transform, table.getVars()) ;
- Iterator<Binding> iter = table.rows() ;
- List<Binding> newRows = new ArrayList<>() ;
- for ( ; iter.hasNext() ; ) {
- Binding b = iter.next() ;
- Binding b2 = transform(b, transform) ;
- newRows.add(b2) ;
- }
- return new TableData(vars, newRows) ;
- }
-
- public static Binding transform(Binding b, NodeTransform transform) {
- BindingMap b2 = BindingFactory.create() ;
- List<Var> vars = Iter.toList(b.vars()) ;
- for ( Var v : vars ) {
- Var v2 = (Var)transform.convert(v) ;
- b2.add(v2, b.get(v));
- }
- return b2 ;
- }
-
-
-
- /** Do a node->node conversion of a List<Quad> - return original List<Quad> for "no change" */
- public static List<Quad> transformQuads(NodeTransform nodeTransform, List<Quad> quads)
- {
- List<Quad> x = new ArrayList<>() ;
- boolean changed = false ;
- for ( Quad q : quads )
- {
- Quad q2 = NodeTransformLib.transform(nodeTransform, q) ;
- if ( q != q2 )
- changed = true ;
- x.add(q2) ;
- }
- if ( ! changed )
- return quads ;
- return x ;
- }
-
- /** Do a node->node conversion of a VarExprList - return original VarExprList for "no change" */
- public static VarExprList transform(NodeTransform nodeTransform, VarExprList varExprList)
- {
- VarExprList varExprList2 = new VarExprList() ;
- boolean changed = false ;
- for ( Var v : varExprList.getVars() )
- {
- Expr expr = varExprList.getExpr(v) ;
- Var v2 = (Var)nodeTransform.convert(v) ;
- Expr expr2 = ( expr != null ) ? transform(nodeTransform, expr) : null ;
-
- if ( ! equal(v, v2) || ! equal(expr, expr2) )
- changed = true ;
- varExprList2.add(v2, expr2) ;
- }
- if ( ! changed )
- return varExprList ;
- return varExprList2 ;
- }
-
- public static List<Var> transformVars(NodeTransform nodeTransform, List<Var> varList)
- {
- List<Var> varList2 = new ArrayList<>(varList.size()) ;
- boolean changed = false ;
- for ( Var v : varList )
- {
- Var v2 = (Var)nodeTransform.convert(v) ;
- varList2.add(v2) ;
- if ( !equal(v, v2) )
- changed = true ;
- }
- if ( ! changed )
- return varList ;
- return varList2 ;
- }
-
- public static ExprList transform(NodeTransform nodeTransform, ExprList exprList)
- {
- ExprList exprList2 = new ExprList() ;
- boolean changed = false ;
- for(Expr expr : exprList)
- {
- Expr expr2 = transform(nodeTransform, expr) ;
- if ( expr != expr2 )
- changed = true ;
- exprList2.add(expr2) ;
- }
- if ( ! changed ) return exprList ;
- return exprList2 ;
- }
-
- public static Expr transform(NodeTransform nodeTransform, Expr expr)
- {
- return expr.applyNodeTransform(nodeTransform) ;
- }
-
- public static List<SortCondition> transform(NodeTransform nodeTransform, List<SortCondition> conditions)
- {
- List<SortCondition> conditions2 = new ArrayList<>() ;
- boolean same = true ;
- for ( SortCondition sc : conditions )
- {
- Expr expr = sc.getExpression() ;
- Expr expr2 = transform(nodeTransform, expr) ;
- if ( expr != expr2 )
- same = false ;
- SortCondition sc2 = new SortCondition(expr2, sc.getDirection()) ;
- conditions2.add(sc2) ;
- }
-
- if ( same )
- return conditions ;
- return conditions2 ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java
deleted file mode 100644
index 30c5149..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/NodeTransformOp.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.graph;
-
-import java.util.ArrayList ;
-import java.util.List ;
-
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.query.SortCondition ;
-import com.hp.hpl.jena.sparql.algebra.Op ;
-import com.hp.hpl.jena.sparql.algebra.Table ;
-import com.hp.hpl.jena.sparql.algebra.TransformCopy ;
-import com.hp.hpl.jena.sparql.algebra.op.* ;
-import com.hp.hpl.jena.sparql.algebra.table.TableUnit ;
-import com.hp.hpl.jena.sparql.core.BasicPattern ;
-import com.hp.hpl.jena.sparql.core.TriplePath ;
-import com.hp.hpl.jena.sparql.core.Var ;
-import com.hp.hpl.jena.sparql.core.VarExprList ;
-import com.hp.hpl.jena.sparql.expr.ExprAggregator ;
-import com.hp.hpl.jena.sparql.expr.ExprList ;
-import com.hp.hpl.jena.sparql.path.Path ;
-
-class NodeTransformOp extends TransformCopy
-{
- // This finds everywhere that node can lurk in an algebra expression:
- // BGPs, paths, triples, quads
- // GRAPH, GRAPH{} (DatasetNames)
- // Filters, including inside EXISTS and expressions in LeftJoin
- // OrderBy, GroupBy
- // Extend, Assign
- // Tables
- // Projects
- // Not:
- // Conditional (no expression)
-
- private final NodeTransform transform ;
- NodeTransformOp(NodeTransform transform)
- {
- this.transform = transform ;
- }
-
- @Override public Op transform(OpTriple opTriple)
- {
- Triple t2 = NodeTransformLib.transform(transform, opTriple.getTriple()) ;
- if ( t2 == opTriple.getTriple())
- return super.transform(opTriple) ;
- return new OpTriple(t2) ;
- }
-
- @Override public Op transform(OpFilter opFilter, Op subOp)
- {
- ExprList exprList = opFilter.getExprs() ;
- ExprList exprList2 = NodeTransformLib.transform(transform, exprList) ;
- if ( exprList2 == exprList )
- return super.transform(opFilter, subOp) ;
- return OpFilter.filter(exprList2, subOp) ;
- }
-
- @Override public Op transform(OpBGP opBGP)
- {
- BasicPattern bgp2 = NodeTransformLib.transform(transform, opBGP.getPattern()) ;
- if ( bgp2 == opBGP.getPattern())
- return super.transform(opBGP) ;
- return new OpBGP(bgp2) ;
- }
-
- @Override public Op transform(OpPath opPath)
- {
- TriplePath tp = opPath.getTriplePath() ;
- Node s = tp.getSubject() ;
- Node s1 = transform.convert(s) ;
- Node o = tp.getObject() ;
- Node o1 = transform.convert(o) ;
-
- if ( s1 == s && o1 == o )
- // No change.
- return super.transform(opPath) ;
-
- Path path = tp.getPath() ;
- TriplePath tp2 ;
-
- if ( path != null )
- tp2 = new TriplePath(s1, path, o1) ;
- else
- {
- Triple t = new Triple(s1, tp.getPredicate(), o1) ;
- tp2 = new TriplePath(t) ;
- }
- return new OpPath(tp2) ;
- }
-
- @Override public Op transform(OpQuadPattern opQuadPattern)
- {
- // The internal representation is (graph, BGP)
- BasicPattern bgp2 = NodeTransformLib.transform(transform, opQuadPattern.getBasicPattern()) ;
- Node g2 = opQuadPattern.getGraphNode() ;
- g2 = transform.convert(g2) ;
-
- if ( g2 == opQuadPattern.getGraphNode() && bgp2 == opQuadPattern.getBasicPattern() )
- return super.transform(opQuadPattern) ;
- return new OpQuadPattern(g2, bgp2) ;
- }
-
- @Override public Op transform(OpGraph opGraph, Op subOp)
- {
- Node g2 = transform.convert(opGraph.getNode()) ;
- if ( g2 == opGraph.getNode() )
- return super.transform(opGraph, subOp) ;
- return new OpGraph(g2, subOp) ;
- }
-
- @Override public Op transform(OpDatasetNames opDatasetNames)
- {
- Node g2 = transform.convert(opDatasetNames.getGraphNode()) ;
- if ( g2 == opDatasetNames.getGraphNode() )
- return super.transform(opDatasetNames) ;
- return new OpDatasetNames(g2) ;
- }
-
- @Override public Op transform(OpTable opTable)
- {
- if ( opTable.isJoinIdentity() )
- return opTable ;
- Table table = opTable.getTable() ;
- if ( table.isEmpty() )
- return opTable ;
- if ( TableUnit.isTableUnit(table) )
- return opTable ;
- if ( table.getVars().size() == 0 )
- return opTable ;
- Table table2 = NodeTransformLib.transform(table, transform) ;
- return OpTable.create(table2) ;
- }
-
- @Override public Op transform(OpLeftJoin opLeftJoin, Op left, Op right)
- {
- ExprList exprList = opLeftJoin.getExprs() ;
- ExprList exprList2 = exprList ;
- if ( exprList != null )
- exprList2 = NodeTransformLib.transform(transform, exprList) ;
- if ( exprList2 == exprList )
- return super.transform(opLeftJoin, left, right) ;
- return OpLeftJoin.create(left, right, exprList2) ;
- }
-
- // Not OpConditional - no expression.
-
- @Override public Op transform(OpProject opProject, Op subOp)
- {
- List<Var> x = opProject.getVars() ;
- List<Var> x2 = NodeTransformLib.transformVars(transform, x) ;
- if ( x == x2 )
- return super.transform(opProject, subOp) ;
- return new OpProject(subOp, x2) ;
- }
-
- @Override public Op transform(OpAssign opAssign, Op subOp)
- {
- VarExprList varExprList = opAssign.getVarExprList() ;
- VarExprList varExprList2 = NodeTransformLib.transform(transform, varExprList) ;
- if ( varExprList == varExprList2 )
- return super.transform(opAssign, subOp) ;
- return OpAssign.assign(subOp, varExprList2) ;
- }
-
- @Override public Op transform(OpExtend opExtend, Op subOp)
- {
- VarExprList varExprList = opExtend.getVarExprList() ;
- VarExprList varExprList2 = NodeTransformLib.transform(transform, varExprList) ;
- if ( varExprList == varExprList2 )
- return super.transform(opExtend, subOp) ;
- return OpExtend.create(subOp, varExprList2) ;
- }
-
- @Override public Op transform(OpOrder opOrder, Op subOp)
- {
- List<SortCondition> conditions = NodeTransformLib.transform(transform, opOrder.getConditions()) ;
-
- if ( conditions == opOrder.getConditions() )
- return super.transform(opOrder, subOp) ;
- return new OpOrder(subOp, conditions) ;
- }
-
- @Override public Op transform(OpGroup opGroup, Op subOp)
- {
- VarExprList groupVars = NodeTransformLib.transform(transform, opGroup.getGroupVars()) ;
- // Rename the vars in the expression as well.
- // .e.g max(?y) ==> max(?/y)
- // These need renaming as well.
- List<ExprAggregator> aggregators = new ArrayList<>() ;
- for ( ExprAggregator agg : opGroup.getAggregators() )
- aggregators.add(agg.applyNodeTransform(transform)) ;
-
- if ( aggregators.equals(opGroup.getAggregators()))
- {
- if ( groupVars == opGroup.getGroupVars() )
- return super.transform(opGroup, subOp) ;
- }
-
- return new OpGroup(subOp, groupVars, aggregators) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/UnmodifiableGraph.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/UnmodifiableGraph.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/UnmodifiableGraph.java
deleted file mode 100644
index 5397575..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/UnmodifiableGraph.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.graph;
-
-import com.hp.hpl.jena.graph.Graph ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.graph.impl.SimpleBulkUpdateHandler ;
-import com.hp.hpl.jena.graph.impl.WrappedGraph ;
-
-public class UnmodifiableGraph extends WrappedGraph
-{
- public UnmodifiableGraph(Graph base)
- {
- super(base) ;
- bud = new SimpleBulkUpdateHandler(this) ;
- }
-
- /** Return base graph that this class protects. Caveat emptor. */
- public Graph unwrap() { return super.base ; }
-
- @Override
- public void performAdd(Triple triple)
- { throw new UnsupportedOperationException() ; }
-
- @Override
- public void performDelete(Triple triple)
- { throw new UnsupportedOperationException() ; }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQ.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQ.java
deleted file mode 100644
index dedf057..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQ.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import java.io.Reader ;
-import java.io.StringReader ;
-
-import com.hp.hpl.jena.query.Query ;
-import com.hp.hpl.jena.query.QueryException ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.query.Syntax ;
-import com.hp.hpl.jena.shared.JenaException ;
-import com.hp.hpl.jena.sparql.lang.arq.ARQParser ;
-import com.hp.hpl.jena.sparql.syntax.Element ;
-import com.hp.hpl.jena.sparql.syntax.Template ;
-
-import org.apache.jena.atlas.logging.Log ;
-
-
-public class ParserARQ extends SPARQLParser
-{
- private interface Action { void exec(ARQParser parser) throws Exception ; }
-
- @Override
- protected Query parse$(final Query query, String queryString)
- {
- query.setSyntax(Syntax.syntaxARQ) ;
-
- Action action = new Action() {
- @Override
- public void exec(ARQParser parser) throws Exception
- {
- parser.QueryUnit() ;
- }
- } ;
-
- perform(query, queryString, action) ;
- validateParsedQuery(query) ;
- return query ;
- }
-
- public static Element parseElement(String string)
- {
- final Query query = new Query () ;
- Action action = new Action() {
- @Override
- public void exec(ARQParser parser) throws Exception
- {
- Element el = parser.GroupGraphPattern() ;
- query.setQueryPattern(el) ;
- }
- } ;
- perform(query, string, action) ;
- return query.getQueryPattern() ;
- }
-
- public static Template parseTemplate(String string)
- {
- final Query query = new Query () ;
- Action action = new Action() {
- @Override
- public void exec(ARQParser parser) throws Exception
- {
- Template t = parser.ConstructTemplate() ;
- query.setConstructTemplate(t) ;
- }
- } ;
- perform(query, string, action) ;
- return query.getConstructTemplate() ;
- }
-
-
- // All throwable handling.
- private static void perform(Query query, String string, Action action)
- {
- Reader in = new StringReader(string) ;
- ARQParser parser = new ARQParser(in) ;
-
- try {
- query.setStrict(true) ;
- parser.setQuery(query) ;
- action.exec(parser) ;
- }
- catch (com.hp.hpl.jena.sparql.lang.arq.ParseException ex)
- {
- throw new QueryParseException(ex.getMessage(),
- ex.currentToken.beginLine,
- ex.currentToken.beginColumn
- ) ; }
- catch (com.hp.hpl.jena.sparql.lang.arq.TokenMgrError tErr)
- {
- // Last valid token : not the same as token error message - but this should not happen
- int col = parser.token.endColumn ;
- int line = parser.token.endLine ;
- throw new QueryParseException(tErr.getMessage(), line, col) ; }
-
- catch (QueryException ex) { throw ex ; }
- catch (JenaException ex) { throw new QueryException(ex.getMessage(), ex) ; }
- catch (Error err)
- {
- // The token stream can throw errors.
- throw new QueryParseException(err.getMessage(), err, -1, -1) ;
- }
- catch (Throwable th)
- {
- Log.warn(ParserSPARQL11.class, "Unexpected throwable: ",th) ;
- throw new QueryException(th.getMessage(), th) ;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQUpdate.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQUpdate.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQUpdate.java
deleted file mode 100644
index 2490445..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserARQUpdate.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import java.io.FileReader ;
-import java.io.Reader ;
-import java.io.StringReader ;
-
-import org.slf4j.LoggerFactory ;
-
-import com.hp.hpl.jena.query.QueryException ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.shared.JenaException ;
-import com.hp.hpl.jena.sparql.lang.arq.ARQParser ;
-import com.hp.hpl.jena.sparql.modify.UpdateSink ;
-
-public class ParserARQUpdate extends UpdateParser
-{
- @Override
- protected void parse$(UpdateSink sink, String queryString)
- {
- Reader r = new StringReader(queryString) ;
- _parse(sink, r) ;
- }
-
- @Override
- protected void parse$(UpdateSink sink, Reader r)
- {
- _parse(sink, r) ;
- }
-
- /** Use with care - Reader must be UTF-8 */
- public void parse(UpdateSink sink, Reader r)
- {
- if ( r instanceof FileReader )
- LoggerFactory.getLogger(this.getClass()).warn("FileReader passed to ParserSPARQLUpdate.parse - use a FileInputStream") ;
- _parse(sink, r) ;
- }
-
- private void _parse(UpdateSink sink, Reader r)
- {
- ARQParser parser = null ;
- try {
- parser = new ARQParser(r) ;
- parser.setUpdateSink(sink) ;
- parser.UpdateUnit() ;
- }
- catch (com.hp.hpl.jena.sparql.lang.arq.ParseException ex)
- {
- throw new QueryParseException(ex.getMessage(),
- ex.currentToken.beginLine,
- ex.currentToken.beginColumn
- ) ; }
- catch (com.hp.hpl.jena.sparql.lang.arq.TokenMgrError tErr)
- {
- // Last valid token : not the same as token error message - but this should not happen
- int col = parser.token.endColumn ;
- int line = parser.token.endLine ;
- throw new QueryParseException(tErr.getMessage(), line, col) ; }
-
- catch (QueryException ex) { throw ex ; }
- catch (JenaException ex) { throw new QueryException(ex.getMessage(), ex) ; }
-// catch (Error err)
-// {
-// // The token stream can throw errors.
-// throw new QueryParseException(err.getMessage(), err, -1, -1) ;
-// }
-// catch (Throwable th)
-// {
-// Log.fatal(this, "Unexpected throwable: ",th) ;
-// throw new QueryException(th.getMessage(), th) ;
-// }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserBase.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserBase.java
deleted file mode 100644
index 1d30c5f..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserBase.java
+++ /dev/null
@@ -1,686 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import java.math.BigInteger ;
-import java.util.HashSet ;
-import java.util.Set ;
-
-import org.apache.jena.atlas.logging.Log ;
-import org.apache.jena.iri.IRI ;
-import org.apache.jena.riot.checker.CheckerIRI ;
-import org.apache.jena.riot.system.ErrorHandler ;
-import org.apache.jena.riot.system.ErrorHandlerFactory ;
-import org.apache.jena.riot.system.RiotLib ;
-import org.slf4j.Logger ;
-import org.slf4j.LoggerFactory ;
-
-import com.hp.hpl.jena.datatypes.RDFDatatype ;
-import com.hp.hpl.jena.datatypes.TypeMapper ;
-import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.NodeFactory ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.n3.JenaURIException ;
-import com.hp.hpl.jena.query.ARQ ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
-import com.hp.hpl.jena.sparql.core.Prologue ;
-import com.hp.hpl.jena.sparql.core.TriplePath ;
-import com.hp.hpl.jena.sparql.core.Var ;
-import com.hp.hpl.jena.sparql.expr.E_Exists ;
-import com.hp.hpl.jena.sparql.expr.E_NotExists ;
-import com.hp.hpl.jena.sparql.expr.Expr ;
-import com.hp.hpl.jena.sparql.graph.NodeConst ;
-import com.hp.hpl.jena.sparql.modify.request.QuadAccSink ;
-import com.hp.hpl.jena.sparql.path.Path ;
-import com.hp.hpl.jena.sparql.syntax.* ;
-import com.hp.hpl.jena.sparql.util.ExprUtils ;
-import com.hp.hpl.jena.sparql.util.LabelToNodeMap ;
-import com.hp.hpl.jena.vocabulary.RDF ;
-
-/** Base class parsers, mainly SPARQL related */
-public class ParserBase
-{
- // NodeConst
- protected final Node XSD_TRUE = NodeConst.nodeTrue ;
- protected final Node XSD_FALSE = NodeConst.nodeFalse ;
-
- protected final Node nRDFtype = NodeConst.nodeRDFType ;
-
- protected final Node nRDFnil = NodeConst.nodeNil ;
- protected final Node nRDFfirst = NodeConst.nodeFirst ;
- protected final Node nRDFrest = NodeConst.nodeRest ;
-
- protected final Node nRDFsubject = RDF.Nodes.subject ;
- protected final Node nRDFpredicate = RDF.Nodes.predicate ;
- protected final Node nRDFobject = RDF.Nodes.object ;
-
- // ----
- // Graph patterns, true; in templates, false.
- private boolean bNodesAreVariables = true ;
- // In DELETE, false.
- private boolean bNodesAreAllowed = true ;
-
- // label => bNode for construct templates patterns
- final LabelToNodeMap bNodeLabels = LabelToNodeMap.createBNodeMap() ;
-
- // label => bNode (as variable) for graph patterns
- final LabelToNodeMap anonVarLabels = LabelToNodeMap.createVarMap() ;
-
- // This is the map used allocate blank node labels during parsing.
- // 1/ It is different between CONSTRUCT and the query pattern
- // 2/ Each BasicGraphPattern is a scope for blank node labels so each
- // BGP causes the map to be cleared at the start of the BGP
-
- LabelToNodeMap activeLabelMap = anonVarLabels ;
- Set<String> previousLabels = new HashSet<>() ;
-
- //LabelToNodeMap listLabelMap = new LabelToNodeMap(true, new VarAlloc("L")) ;
- // ----
-
- public ParserBase() {}
-
- protected Prologue prologue ;
- public void setPrologue(Prologue prologue) { this.prologue = prologue ; }
- public Prologue getPrologue() { return prologue ; }
-
- protected void setInConstructTemplate(boolean b)
- {
- setBNodesAreVariables(!b) ;
- }
-
- protected boolean getBNodesAreVariables() { return bNodesAreVariables ; }
- protected void setBNodesAreVariables(boolean bNodesAreVariables)
- {
- this.bNodesAreVariables = bNodesAreVariables ;
- if ( bNodesAreVariables )
- activeLabelMap = anonVarLabels ;
- else
- activeLabelMap = bNodeLabels ;
- }
-
- protected boolean getBNodesAreAllowed() { return bNodesAreAllowed ; }
- protected void setBNodesAreAllowed(boolean bNodesAreAllowed)
- {
- this.bNodesAreAllowed = bNodesAreAllowed ;
- }
-
- protected Element compressGroupOfOneGroup(ElementGroup elg)
- {
- // remove group of one group.
- if ( elg.getElements().size() == 1 )
- {
- Element e1 = elg.getElements().get(0) ;
- if ( e1 instanceof ElementGroup )
- return e1 ;
- }
- return elg ;
- }
-
- protected Node createLiteralInteger(String lexicalForm)
- {
- return NodeFactory.createLiteral(lexicalForm, XSDDatatype.XSDinteger) ;
- }
-
- protected Node createLiteralDouble(String lexicalForm)
- {
- return NodeFactory.createLiteral(lexicalForm, XSDDatatype.XSDdouble) ;
- }
-
- protected Node createLiteralDecimal(String lexicalForm)
- {
- return NodeFactory.createLiteral(lexicalForm, XSDDatatype.XSDdecimal) ;
- }
-
- protected Node stripSign(Node node)
- {
- if ( ! node.isLiteral() ) return node ;
- String lex = node.getLiteralLexicalForm() ;
- String lang = node.getLiteralLanguage() ;
- RDFDatatype dt = node.getLiteralDatatype() ;
-
- if ( ! lex.startsWith("-") && ! lex.startsWith("+") )
- throw new ARQInternalErrorException("Literal does not start with a sign: "+lex) ;
-
- lex = lex.substring(1) ;
- return NodeFactory.createLiteral(lex, lang, dt) ;
- }
-
- protected Node createLiteral(String lexicalForm, String langTag, String datatypeURI)
- {
- Node n = null ;
- // Can't have type and lang tag in parsing.
- if ( datatypeURI != null)
- {
- RDFDatatype dType = TypeMapper.getInstance().getSafeTypeByName(datatypeURI) ;
- n = NodeFactory.createLiteral(lexicalForm, dType) ;
- }
- else if ( langTag != null && ! langTag.isEmpty() )
- n = NodeFactory.createLiteral(lexicalForm, langTag) ;
- else
- n = NodeFactory.createLiteral(lexicalForm) ;
- return n ;
- }
-
- protected long integerValue(String s)
- {
- try {
- if ( s.startsWith("+") )
- s = s.substring(1) ;
- if ( s.startsWith("0x") )
- {
- // Hex
- s = s.substring(2) ;
- return Long.parseLong(s, 16) ;
- }
- return Long.parseLong(s) ;
- } catch (NumberFormatException ex)
- {
- try {
- // Possible too large for a long.
- BigInteger integer = new BigInteger(s) ;
- throwParseException("Number '"+s+"' is a valid number but can't not be stored in a long") ;
- } catch (NumberFormatException ex2) {}
- throw new QueryParseException(ex, -1, -1) ;
- }
- }
-
- protected double doubleValue(String s)
- {
- if ( s.startsWith("+") )
- s = s.substring(1) ;
- double valDouble = Double.parseDouble(s) ;
- return valDouble ;
- }
-
- /** Remove first and last characters (e.g. ' or "") from a string */
- protected static String stripQuotes(String s)
- {
- return s.substring(1,s.length()-1) ;
- }
-
- /** Remove first 3 and last 3 characters (e.g. ''' or """) from a string */
- protected static String stripQuotes3(String s)
- {
- return s.substring(3,s.length()-3) ;
- }
-
- /** remove the first n charcacters from the string*/
- public static String stripChars(String s, int n)
- {
- return s.substring(n, s.length()) ;
- }
-
- protected Var createVariable(String s, int line, int column)
- {
- s = s.substring(1) ; // Drop the marker
-
- // This is done by the parser input stream nowadays.
- //s = unescapeCodePoint(s, line, column) ;
- // Check \ u did not put in any illegals.
- return Var.alloc(s) ;
- }
-
- // ---- IRIs and Nodes
- // See RiotLib re bNode IRIs.
- // Merge sometime.
-
- protected String resolveQuotedIRI(String iriStr, int line, int column)
- {
- iriStr = stripQuotes(iriStr) ;
- return resolveIRI(iriStr, line, column) ;
- }
-
- public static final String ParserLoggerName = "SPARQL" ;
- private static Logger parserLog = LoggerFactory.getLogger(ParserLoggerName) ;
- private static ErrorHandler errorHandler = ErrorHandlerFactory.errorHandlerStd(parserLog) ;
-
- protected String resolveIRI(String iriStr, int line, int column)
- {
- if ( isBNodeIRI(iriStr) )
- return iriStr ;
-
- if ( getPrologue() != null )
- {
- if ( getPrologue().getResolver() != null )
- try {
- // Used to be errors (pre Jena 2.12.0)
- // .resolve(iriStr)
- IRI iri = getPrologue().getResolver().resolveSilent(iriStr) ;
- if ( true )
- CheckerIRI.iriViolations(iri, errorHandler, line, column) ;
- iriStr = iri.toString() ;
- } catch (JenaURIException ex)
- { throwParseException(ex.getMessage(), line, column) ; }
- }
- return iriStr ;
- }
-
- protected String resolvePName(String qname, int line, int column)
- {
- // It's legal.
- int idx = qname.indexOf(':') ;
-
- // -- Escapes in local name
- String prefix = qname.substring(0, idx) ;
- String local = qname.substring(idx+1) ;
- local = unescapePName(local, line, column) ;
- qname = prefix+":"+local ;
- // --
-
- String s = getPrologue().expandPrefixedName(qname) ;
- if ( s == null )
- throwParseException("Unresolved prefixed name: "+qname, line, column) ;
- return s ;
- }
-
- boolean skolomizedBNodes = ARQ.isTrue(ARQ.constantBNodeLabels) ;
- protected Node createNode(String iri)
- {
- if ( skolomizedBNodes )
- return RiotLib.createIRIorBNode(iri) ;
- else
- return NodeFactory.createURI(iri) ;
- }
-
- protected boolean isBNodeIRI(String iri)
- {
- return skolomizedBNodes && RiotLib.isBNodeIRI(iri) ;
- }
-
- // -------- Basic Graph Patterns and Blank Node label scopes
-
- // A BasicGraphPattern is any sequence of TripleBlocks, separated by filters,
- // but not by other graph patterns.
-
- protected void startBasicGraphPattern()
- { activeLabelMap.clear() ; }
-
- protected void endBasicGraphPattern()
- { previousLabels.addAll(activeLabelMap.getLabels()) ; }
-
- protected void startTriplesBlock()
- { }
-
- protected void endTriplesBlock()
- { }
-
- // On entry to a new group, the current BGP is ended.
- protected void startGroup(ElementGroup elg)
- {
- endBasicGraphPattern() ;
- startBasicGraphPattern() ;
- }
-
- protected void endGroup(ElementGroup elg)
- {
- endBasicGraphPattern() ;
- }
-
- // --------
-
- // BNode from a list
-// protected Node createListNode()
-// { return listLabelMap.allocNode() ; }
-
- protected Node createListNode(int line, int column) { return createBNode(line, column) ; }
-
- // Unlabelled bNode.
- protected Node createBNode(int line, int column)
- {
- if ( ! bNodesAreAllowed )
- throwParseException("Blank nodes not allowed in DELETE templates", line, column) ;
- return activeLabelMap.allocNode() ;
- }
-
- // Labelled bNode.
- protected Node createBNode(String label, int line, int column)
- {
- if ( ! bNodesAreAllowed )
- throwParseException("Blank nodes not allowed in DELETE templates: "+label, line, column) ;
- if ( previousLabels.contains(label) )
- throwParseException("Blank node label reuse not allowed at this point: "+label,
- line, column) ;
-
- //label = unescapeCodePoint(label, line, column) ;
- return activeLabelMap.asNode(label) ;
- }
-
- protected Expr createExprExists(Element element)
- {
- return new E_Exists(element) ;
- }
-
- protected Expr createExprNotExists(Element element)
- {
- // Could negate here.
- return new E_NotExists(element) ;
- }
-
- protected String fixupPrefix(String prefix, int line, int column)
- {
- // \ u processing!
- if ( prefix.endsWith(":") )
- prefix = prefix.substring(0, prefix.length()-1) ;
- return prefix ;
- }
-
- protected void setAccGraph(QuadAccSink acc, Node gn)
- {
- acc.setGraph(gn) ;
- }
-
- protected void insert(TripleCollector acc, Node s, Node p, Node o)
- {
- acc.addTriple(new Triple(s, p, o)) ;
- }
-
- protected void insert(TripleCollectorMark acc, int index, Node s, Node p, Node o)
- {
- acc.addTriple(index, new Triple(s, p, o)) ;
- }
-
- protected void insert(TripleCollector acc, Node s, Node p, Path path, Node o)
- {
- if ( p == null )
- acc.addTriplePath(new TriplePath(s, path, o)) ;
- else
- acc.addTriple(new Triple(s, p, o)) ;
- }
-
- protected void insert(TripleCollectorMark acc, int index, Node s, Node p, Path path, Node o)
- {
- if ( p == null )
- acc.addTriplePath(index, new TriplePath(s, path, o)) ;
- else
- acc.addTriple(index, new Triple(s, p, o)) ;
- }
-
- protected void insert(TripleCollector target, ElementPathBlock source)
- {
- for (TriplePath path : source.getPattern())
- {
- if (path.isTriple())
- {
- target.addTriple(path.asTriple());
- }
- else
- {
- target.addTriplePath(path);
- }
- }
- }
-
- protected Expr asExpr(Node n)
- {
- return ExprUtils.nodeToExpr(n) ;
- }
-
- protected Expr asExprNoSign(Node n)
- {
- String lex = n.getLiteralLexicalForm() ;
- String lang = n.getLiteralLanguage() ;
- String dtURI = n.getLiteralDatatypeURI() ;
- n = createLiteral(lex, lang, dtURI) ;
- return ExprUtils.nodeToExpr(n) ;
- }
-
- // Utilities to remove escapes in strings.
-
- public static String unescapeStr(String s)
- { return unescape(s, '\\', false, 1, 1) ; }
-
-// public static String unescapeCodePoint(String s)
-// { return unescape(s, '\\', true, 1, 1) ; }
-//
-// protected String unescapeCodePoint(String s, int line, int column)
-// { return unescape(s, '\\', true, line, column) ; }
-
-
- public static String unescapeStr(String s, int line, int column)
- { return unescape(s, '\\', false, line, column) ; }
-
- // Worker function
- public static String unescape(String s, char escape, boolean pointCodeOnly, int line, int column)
- {
- int i = s.indexOf(escape) ;
-
- if ( i == -1 )
- return s ;
-
- // Dump the initial part straight into the string buffer
- StringBuilder sb = new StringBuilder(s.substring(0,i)) ;
-
- for ( ; i < s.length() ; i++ )
- {
- char ch = s.charAt(i) ;
- // Keep line and column numbers.
- switch (ch)
- {
- case '\n':
- case '\r':
- line++ ;
- column = 1 ;
- break ;
- default:
- column++ ;
- break ;
- }
-
- if ( ch != escape )
- {
- sb.append(ch) ;
- continue ;
- }
-
- // Escape
- if ( i >= s.length()-1 )
- throwParseException("Illegal escape at end of string", line, column) ;
- char ch2 = s.charAt(i+1) ;
- column = column+1 ;
- i = i + 1 ;
-
- // \\u and \\U
- if ( ch2 == 'u' )
- {
- // i points to the \ so i+6 is next character
- if ( i+4 >= s.length() )
- throwParseException("\\u escape too short", line, column) ;
- int x = hex(s, i+1, 4, line, column) ;
- sb.append((char)x) ;
- // Jump 1 2 3 4 -- already skipped \ and u
- i = i+4 ;
- column = column+4 ;
- continue ;
- }
- if ( ch2 == 'U' )
- {
- // i points to the \ so i+6 is next character
- if ( i+8 >= s.length() )
- throwParseException("\\U escape too short", line, column) ;
- int x = hex(s, i+1, 8, line, column) ;
- // Convert to UTF-16 codepoint pair.
- sb.append((char)x) ;
- // Jump 1 2 3 4 5 6 7 8 -- already skipped \ and u
- i = i+8 ;
- column = column+8 ;
- continue ;
- }
-
- // Are we doing just point code escapes?
- // If so, \X-anything else is legal as a literal "\" and "X"
-
- if ( pointCodeOnly )
- {
- sb.append('\\') ;
- sb.append(ch2) ;
- i = i + 1 ;
- continue ;
- }
-
- // Not just codepoints. Must be a legal escape.
- char ch3 = 0 ;
- switch (ch2)
- {
- case 'n': ch3 = '\n' ; break ;
- case 't': ch3 = '\t' ; break ;
- case 'r': ch3 = '\r' ; break ;
- case 'b': ch3 = '\b' ; break ;
- case 'f': ch3 = '\f' ; break ;
- case '\'': ch3 = '\'' ; break ;
- case '\"': ch3 = '\"' ; break ;
- case '\\': ch3 = '\\' ; break ;
- default:
- throwParseException("Unknown escape: \\"+ch2, line, column) ;
- }
- sb.append(ch3) ;
- }
- return sb.toString() ;
- }
-
- // Line and column that started the escape
- public static int hex(String s, int i, int len, int line, int column)
- {
-// if ( i+len >= s.length() )
-// {
-//
-// }
- int x = 0 ;
- for ( int j = i ; j < i+len ; j++ )
- {
- char ch = s.charAt(j) ;
- column++ ;
- int k = 0 ;
- switch (ch)
- {
- case '0': k = 0 ; break ;
- case '1': k = 1 ; break ;
- case '2': k = 2 ; break ;
- case '3': k = 3 ; break ;
- case '4': k = 4 ; break ;
- case '5': k = 5 ; break ;
- case '6': k = 6 ; break ;
- case '7': k = 7 ; break ;
- case '8': k = 8 ; break ;
- case '9': k = 9 ; break ;
- case 'A': case 'a': k = 10 ; break ;
- case 'B': case 'b': k = 11 ; break ;
- case 'C': case 'c': k = 12 ; break ;
- case 'D': case 'd': k = 13 ; break ;
- case 'E': case 'e': k = 14 ; break ;
- case 'F': case 'f': k = 15 ; break ;
- default:
- throwParseException("Illegal hex escape: "+ch, line, column) ;
- }
- x = (x<<4)+k ;
- }
- return x ;
- }
-
- public static String unescapePName(String s, int line, int column)
- {
- char escape = '\\' ;
- int idx = s.indexOf(escape) ;
-
- if ( idx == -1 )
- return s ;
-
- int len = s.length() ;
- StringBuilder sb = new StringBuilder() ;
-
- for ( int i = 0 ; i < len ; i++ )
- {
- // Copied form unescape abobve - share!
- char ch = s.charAt(i) ;
- // Keep line and column numbers.
- switch (ch)
- {
- case '\n':
- case '\r':
- line++ ;
- column = 1 ;
- break ;
- default:
- column++ ;
- break ;
- }
-
- if ( ch != escape )
- {
- sb.append(ch) ;
- continue ;
- }
-
- // Escape
- if ( i >= s.length()-1 )
- throwParseException("Illegal escape at end of string", line, column) ;
- char ch2 = s.charAt(i+1) ;
- column = column+1 ;
- i = i + 1 ;
-
- switch (ch2)
- {
- case '~' :
- case '.' :
- case '-' :
- case '!' :
- case '$' :
- case '&' :
- case '\'' :
- case '(' :
- case ')' :
- case '*' :
- case '+' :
- case ',' :
- case ';' :
- case '=' :
- case ':' :
- case '/' :
- case '?' :
- case '#' :
- case '@' :
- case '%' :
- sb.append(ch2) ;
- break ;
- default:
- throwParseException("Illegal prefix name escape: "+ch2, line, column) ;
- }
- }
- return sb.toString() ;
- }
-
-
- protected void warnDeprecation(String msg)
- {
- Log.warn(this, msg) ;
- }
-
- public static void throwParseException(String msg, int line, int column)
- {
- throw new QueryParseException("Line " + line + ", column " + column + ": " + msg,
- line, column) ;
- }
-
- public static void throwParseException(String msg)
- {
- throw new QueryParseException(msg, -1, -1) ;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL10.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL10.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL10.java
deleted file mode 100644
index dab7c31..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL10.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import java.io.Reader ;
-import java.io.StringReader ;
-
-import com.hp.hpl.jena.query.Query ;
-import com.hp.hpl.jena.query.QueryException ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.query.Syntax ;
-import com.hp.hpl.jena.shared.JenaException ;
-import com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10 ;
-import com.hp.hpl.jena.sparql.syntax.Element ;
-import com.hp.hpl.jena.sparql.syntax.Template ;
-
-import org.apache.jena.atlas.logging.Log ;
-
-
-public class ParserSPARQL10 extends SPARQLParser
-{
- private interface Action { void exec(SPARQLParser10 parser) throws Exception ; }
-
- @Override
- protected Query parse$(final Query query, String queryString)
- {
- query.setSyntax(Syntax.syntaxSPARQL_10) ;
-
- Action action = new Action() {
- @Override
- public void exec(SPARQLParser10 parser) throws Exception
- {
- parser.QueryUnit() ;
- }
- } ;
-
- perform(query, queryString, action) ;
- validateParsedQuery(query) ;
- return query ;
- }
-
- public static Element parseElement(String string)
- {
- final Query query = new Query () ;
- Action action = new Action() {
- @Override
- public void exec(SPARQLParser10 parser) throws Exception
- {
- Element el = parser.GroupGraphPattern() ;
- query.setQueryPattern(el) ;
- }
- } ;
- perform(query, string, action) ;
- return query.getQueryPattern() ;
- }
-
- public static Template parseTemplate(String string)
- {
- final Query query = new Query () ;
- Action action = new Action() {
- @Override
- public void exec(SPARQLParser10 parser) throws Exception
- {
- Template t = parser.ConstructTemplate() ;
- query.setConstructTemplate(t) ;
- }
- } ;
- perform(query, string, action) ;
- return query.getConstructTemplate() ;
- }
-
- // All throwable handling.
- private static void perform(Query query, String string, Action action)
- {
- Reader in = new StringReader(string) ;
- SPARQLParser10 parser = new SPARQLParser10(in) ;
-
- try {
- query.setStrict(true) ;
- parser.setQuery(query) ;
- action.exec(parser) ;
- }
- catch (com.hp.hpl.jena.sparql.lang.sparql_10.ParseException ex)
- {
- throw new QueryParseException(ex.getMessage(),
- ex.currentToken.beginLine,
- ex.currentToken.beginColumn
- ) ; }
- catch (com.hp.hpl.jena.sparql.lang.sparql_10.TokenMgrError tErr)
- {
- // Last valid token : not the same as token error message - but this should not happen
- int col = parser.token.endColumn ;
- int line = parser.token.endLine ;
- throw new QueryParseException(tErr.getMessage(), line, col) ; }
-
- catch (QueryException ex) { throw ex ; }
- catch (JenaException ex) { throw new QueryException(ex.getMessage(), ex) ; }
- catch (Error err)
- {
- // The token stream can throw errors.
- throw new QueryParseException(err.getMessage(), err, -1, -1) ;
- }
- catch (Throwable th)
- {
- Log.warn(ParserSPARQL10.class, "Unexpected throwable: ",th) ;
- throw new QueryException(th.getMessage(), th) ;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11.java
deleted file mode 100644
index bfe0d34..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import java.io.Reader ;
-import java.io.StringReader ;
-
-import org.apache.jena.atlas.logging.Log ;
-
-import com.hp.hpl.jena.query.Query ;
-import com.hp.hpl.jena.query.QueryException ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.query.Syntax ;
-import com.hp.hpl.jena.shared.JenaException ;
-import com.hp.hpl.jena.sparql.lang.sparql_11.SPARQLParser11 ;
-import com.hp.hpl.jena.sparql.syntax.Element ;
-import com.hp.hpl.jena.sparql.syntax.Template ;
-
-
-public class ParserSPARQL11 extends SPARQLParser
-{
- private interface Action { void exec(SPARQLParser11 parser) throws Exception ; }
-
- @Override
- protected Query parse$(final Query query, String queryString)
- {
- query.setSyntax(Syntax.syntaxSPARQL_11) ;
-
- Action action = new Action() {
- @Override
- public void exec(SPARQLParser11 parser) throws Exception
- {
- parser.QueryUnit() ;
- }
- } ;
-
- perform(query, queryString, action) ;
- validateParsedQuery(query) ;
- return query ;
- }
-
- public static Element parseElement(String string)
- {
- final Query query = new Query () ;
- Action action = new Action() {
- @Override
- public void exec(SPARQLParser11 parser) throws Exception
- {
- Element el = parser.GroupGraphPattern() ;
- query.setQueryPattern(el) ;
- }
- } ;
- perform(query, string, action) ;
- return query.getQueryPattern() ;
- }
-
- public static Template parseTemplate(String string)
- {
- final Query query = new Query () ;
- Action action = new Action() {
- @Override
- public void exec(SPARQLParser11 parser) throws Exception
- {
- Template t = parser.ConstructTemplate() ;
- query.setConstructTemplate(t) ;
- }
- } ;
- perform(query, string, action) ;
- return query.getConstructTemplate() ;
- }
-
-
- // All throwable handling.
- private static void perform(Query query, String string, Action action)
- {
- Reader in = new StringReader(string) ;
- SPARQLParser11 parser = new SPARQLParser11(in) ;
-
- try {
- query.setStrict(true) ;
- parser.setQuery(query) ;
- action.exec(parser) ;
- }
- catch (com.hp.hpl.jena.sparql.lang.sparql_11.ParseException ex)
- {
- throw new QueryParseException(ex.getMessage(),
- ex.currentToken.beginLine,
- ex.currentToken.beginColumn
- ) ; }
- catch (com.hp.hpl.jena.sparql.lang.sparql_11.TokenMgrError tErr)
- {
- // Last valid token : not the same as token error message - but this should not happen
- int col = parser.token.endColumn ;
- int line = parser.token.endLine ;
- throw new QueryParseException(tErr.getMessage(), line, col) ; }
-
- catch (QueryException ex) { throw ex ; }
- catch (JenaException ex) { throw new QueryException(ex.getMessage(), ex) ; }
- catch (Error err)
- {
- // The token stream can throw errors.
- throw new QueryParseException(err.getMessage(), err, -1, -1) ;
- }
- catch (Throwable th)
- {
- Log.warn(ParserSPARQL11.class, "Unexpected throwable: ",th) ;
- throw new QueryException(th.getMessage(), th) ;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11Update.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11Update.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11Update.java
deleted file mode 100644
index 6d7ce29..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/ParserSPARQL11Update.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import java.io.FileReader ;
-import java.io.Reader ;
-import java.io.StringReader ;
-
-import org.apache.jena.atlas.logging.Log ;
-import org.slf4j.LoggerFactory ;
-
-import com.hp.hpl.jena.query.QueryException ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.shared.JenaException ;
-import com.hp.hpl.jena.sparql.lang.sparql_11.SPARQLParser11 ;
-import com.hp.hpl.jena.sparql.modify.UpdateSink ;
-import com.hp.hpl.jena.update.UpdateException ;
-
-
-public class ParserSPARQL11Update extends UpdateParser
-{
- @Override
- protected void parse$(UpdateSink sink, String updateString) {
- Reader r = new StringReader(updateString) ;
- _parse(sink, r) ;
- }
-
- @Override
- protected void parse$(UpdateSink sink, Reader r) {
- _parse(sink, r) ;
- }
-
- public void parse(UpdateSink sink, Reader r) {
- if ( r instanceof FileReader )
- LoggerFactory.getLogger(this.getClass()).warn("FileReader passed to ParserSPARQL11Update.parse - use a FileInputStream") ;
- _parse(sink, r) ;
- }
-
- private void _parse(UpdateSink sink, Reader r) {
- SPARQLParser11 parser = null ;
- try {
- parser = new SPARQLParser11(r) ;
- parser.setUpdateSink(sink) ;
- parser.UpdateUnit() ;
- }
- catch (com.hp.hpl.jena.sparql.lang.sparql_11.ParseException ex)
- {
- throw new QueryParseException(ex.getMessage(),
- ex.currentToken.beginLine,
- ex.currentToken.beginColumn) ;
- }
- catch (com.hp.hpl.jena.sparql.lang.sparql_11.TokenMgrError tErr)
- {
- // Last valid token : not the same as token error message - but this should not happen
- int col = parser.token.endColumn ;
- int line = parser.token.endLine ;
- throw new QueryParseException(tErr.getMessage(), line, col) ; }
-
- catch (UpdateException ex) { throw ex ; }
- catch (JenaException ex) { throw new QueryException(ex.getMessage(), ex) ; }
- catch (Error err)
- {
- // The token stream can throw errors.
- throw new QueryParseException(err.getMessage(), err, -1, -1) ;
- }
- catch (Throwable th)
- {
- Log.fatal(this, "Unexpected throwable: ",th) ;
- throw new QueryException(th.getMessage(), th) ;
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParser.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParser.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParser.java
deleted file mode 100644
index aa98e01..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParser.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import com.hp.hpl.jena.query.Query ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.query.Syntax ;
-
-/** This class provides the root of lower level access to all the parsers.
- * Each subclass hides the details of the per-language exception handlers and other
- * javacc details to provide a methods that deal with setting up Query objects
- * and using QueryException exceptions for problems. */
-
-public abstract class SPARQLParser
-{
- public final Query parse(Query query, String queryString) throws QueryParseException
- {
- return parse$(query, queryString) ;
- }
-
- protected abstract Query parse$(Query query, String queryString) throws QueryParseException ;
-
-
- public static boolean canParse(Syntax syntaxURI)
- {
- return SPARQLParserRegistry.get().containsFactory(syntaxURI) ;
- }
-
- public static SPARQLParser createParser(Syntax syntaxURI)
- {
- return SPARQLParserRegistry.get().createParser(syntaxURI) ;
- }
-
- // Do any testing of queries after the construction of the parse tree.
- protected void validateParsedQuery(Query query)
- {
- SyntaxVarScope.check(query) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserBase.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserBase.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserBase.java
deleted file mode 100644
index 401a660..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserBase.java
+++ /dev/null
@@ -1,320 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import java.util.ArrayDeque ;
-import java.util.ArrayList ;
-import java.util.Deque ;
-import java.util.HashSet ;
-import java.util.List ;
-import java.util.Set ;
-
-import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.query.Query ;
-import com.hp.hpl.jena.query.QueryParseException ;
-import com.hp.hpl.jena.sparql.ARQInternalErrorException ;
-import com.hp.hpl.jena.sparql.core.Prologue;
-import com.hp.hpl.jena.sparql.core.Var ;
-import com.hp.hpl.jena.sparql.engine.binding.Binding ;
-import com.hp.hpl.jena.sparql.engine.binding.BindingFactory ;
-import com.hp.hpl.jena.sparql.engine.binding.BindingMap ;
-import com.hp.hpl.jena.sparql.modify.UpdateSink ;
-import com.hp.hpl.jena.sparql.modify.request.QuadAcc ;
-import com.hp.hpl.jena.sparql.modify.request.QuadDataAccSink ;
-import com.hp.hpl.jena.sparql.util.LabelToNodeMap ;
-import com.hp.hpl.jena.update.Update ;
-
-/** Class that has all the parse event operations and other query/update specific things */
-public class SPARQLParserBase extends ParserBase
-{
- private Deque<Query> stack = new ArrayDeque<>() ;
- protected Query query ;
-
- protected SPARQLParserBase() {}
-
- public void setQuery(Query q)
- {
- query = q ;
- setPrologue(q) ;
- }
-
- public Query getQuery() { return query ; }
-
- // The ARQ parser is both query and update languages.
-
-// // ---- SPARQL/Update (Submission)
-// private UpdateRequest requestSubmission = null ;
-//
-// protected UpdateRequest getUpdateRequestSubmission() { return requestSubmission ; }
-// public void setUpdateRequest(UpdateRequest request)
-// {
-// setPrologue(request) ;
-// this.requestSubmission = request ;
-// // And create a query because we may have nested selects.
-// this.query = new Query () ;
-// }
-
- // SPARQL Update (W3C RECommendation)
- private UpdateSink sink = null ;
-
- // Places to push settings across points where we reset.
- private boolean oldBNodesAreVariables ;
- private boolean oldBNodesAreAllowed ;
-
- // Count of subSelect nesting.
- // Level 0 is top level.
- // Level -1 is not in a pattern WHERE clause.
- private int queryLevel = -1 ;
- private Deque<Set<String>> stackPreviousLabels = new ArrayDeque<>() ;
- private Deque<LabelToNodeMap> stackCurrentLabels = new ArrayDeque<>() ;
-
-// protected UpdateSink getUpdateSink() { return sink ; }
- public void setUpdateSink(UpdateSink sink)
- {
- this.sink = sink ;
- this.query = new Query() ;
- setPrologue(sink.getPrologue()) ;
- }
-
- // Signal start/finish of units
-
- protected void startQuery() {}
- protected void finishQuery() {}
-
- protected void startUpdateRequest() {}
- protected void finishUpdateRequest() {}
-
-// protected void startBasicGraphPattern()
-// { activeLabelMap.clear() ; }
-//
-// protected void endBasicGraphPattern()
-// { oldLabels.addAll(activeLabelMap.getLabels()) ; }
-
- protected void startUpdateOperation() {}
- protected void finishUpdateOperation() {}
-
- protected void startModifyUpdate() { }
- protected void finishModifyUpdate() { }
-
- protected void startDataInsert(QuadDataAccSink qd, int line, int col)
- {
- oldBNodesAreVariables = getBNodesAreVariables() ;
- setBNodesAreVariables(false) ;
- activeLabelMap.clear() ;
- }
-
- protected void finishDataInsert(QuadDataAccSink qd, int line, int col)
- {
- previousLabels.addAll(activeLabelMap.getLabels()) ;
- activeLabelMap.clear() ;
- setBNodesAreVariables(oldBNodesAreVariables) ;
- }
-
- protected void startDataDelete(QuadDataAccSink qd,int line, int col)
- {
- oldBNodesAreAllowed = getBNodesAreAllowed() ;
- setBNodesAreAllowed(false) ;
- }
-
- protected void finishDataDelete(QuadDataAccSink qd, int line, int col)
- {
- setBNodesAreAllowed(oldBNodesAreAllowed) ;
- }
-
- // These can be nested with subSELECTs but subSELECTs share bNodeLabel state.
- protected void startWherePattern()
- {
- queryLevel += 1 ;
- if ( queryLevel == 0 )
- {
- pushLabelState() ;
- clearLabelState() ;
- }
- }
-
- protected void finishWherePattern()
- {
- if ( queryLevel == 0 )
- popLabelState() ;
- queryLevel -= 1 ;
- }
-
- // This holds the accumulation of labels from earlier INSERT DATA
- // across template creation (bNode in templates get cloned before
- // going into the data).
-
- protected void startInsertTemplate(QuadAcc qd, int line, int col)
- {
- oldBNodesAreVariables = getBNodesAreVariables() ;
- setBNodesAreVariables(false) ;
- pushLabelState() ;
- }
-
- protected void finishInsertTemplate(QuadAcc qd, int line, int col)
- {
- // Restore accumulated labels.
- popLabelState() ;
- // This also set the bnode syntax to node functionality - must be after popLabelState.
- setBNodesAreVariables(oldBNodesAreVariables) ;
- }
-
- // No bNodes in delete templates.
- protected void startDeleteTemplate(QuadAcc qd, int line, int col)
- {
- oldBNodesAreAllowed = getBNodesAreAllowed() ;
- setBNodesAreAllowed(false) ;
- }
-
- protected void finishDeleteTemplate(QuadAcc qd, int line, int col)
- {
- setBNodesAreAllowed(oldBNodesAreAllowed) ;
- }
-
- protected void emitUpdate(Update update)
- {
- // The parser can send null if it already performed an INSERT_DATA or DELETE_DATA
- if (null != update)
- {
- sink.send(update);
- }
- }
-
- protected QuadDataAccSink createInsertDataSink()
- {
- return sink.createInsertDataSink();
- }
-
- protected QuadDataAccSink createDeleteDataSink()
- {
- return sink.createDeleteDataSink();
- }
-
- protected void pushQuery()
- {
- if ( query == null )
- throw new ARQInternalErrorException("Parser query object is null") ;
- stack.push(query) ;
- }
-
- protected void startSubSelect(int line, int col)
- {
- pushQuery();
- query = newSubQuery(getPrologue()) ;
- }
-
- protected Query newSubQuery(Prologue progloue)
- {
- return new Query(getPrologue());
- }
-
- protected void popQuery()
- {
- query = stack.pop();
- }
-
- protected Query endSubSelect(int line, int column)
- {
- Query subQuery = query ;
- if ( ! subQuery.isSelectType() )
- throwParseException("Subquery not a SELECT query", line, column) ;
- popQuery();
- return subQuery ;
- }
-
- private List<Var> variables = null ;
- private List<Binding> values = null ;
- private int currentColumn = -1 ;
-
- protected void startValuesClause(int line, int col)
- {
- variables = new ArrayList<>() ;
- values = new ArrayList<>() ;
- }
-
- protected void finishValuesClause(int line, int col)
- {
- getQuery().setValuesDataBlock(variables, values) ;
- }
-
- protected void startInlineData(List<Var> vars, List<Binding> rows, int line, int col)
- {
- variables = vars ;
- values = rows ;
- }
-
- protected void finishInlineData(int line, int col)
- {}
-
- private BindingMap currentValueRow() { return (BindingMap)values.get(values.size()-1) ; }
-
- protected void emitDataBlockVariable(Var v) { variables.add(v) ; }
-
- protected void startDataBlockValueRow(int line, int col)
- {
- values.add(BindingFactory.create()) ;
- currentColumn = -1 ;
- }
-
- protected void emitDataBlockValue(Node n, int line, int col)
- {
- currentColumn++ ;
-
- if ( currentColumn >= variables.size() )
- // Exception will be thrown later when we have the complete row count.
- return ;
-
- Var v = variables.get(currentColumn) ;
- if ( n != null )
- currentValueRow().add(v, n) ;
-
- }
-
- protected void finishDataBlockValueRow(int line, int col)
- {
- //if ( variables.size() != currentValueRow().size() )
-
- if ( currentColumn+1 != variables.size() )
- {
- String msg = String.format("Mismatch: %d variables but %d values",variables.size(), currentColumn+1) ;
- msg = QueryParseException.formatMessage(msg, line, col) ;
- throw new QueryParseException(msg, line , col) ;
- }
- }
-
- private void pushLabelState()
- {
- // Hide used labels already tracked.
- stackPreviousLabels.push(previousLabels) ;
- stackCurrentLabels.push(activeLabelMap) ;
- previousLabels = new HashSet<>() ;
- activeLabelMap.clear() ;
- }
-
- private void popLabelState()
- {
- previousLabels = stackPreviousLabels.pop() ;
- activeLabelMap = stackCurrentLabels.pop();
- }
-
- private void clearLabelState()
- {
- activeLabelMap.clear() ;
- previousLabels.clear() ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/56534eac/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserFactory.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserFactory.java b/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserFactory.java
deleted file mode 100644
index db1e817..0000000
--- a/jena-arq/src/main/java/com/hp/hpl/jena/sparql/lang/SPARQLParserFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 com.hp.hpl.jena.sparql.lang;
-
-import com.hp.hpl.jena.query.Syntax ;
-
-public interface SPARQLParserFactory
-{
- /** Return true if this factory can create a parser for the given syntax */
- public boolean accept ( Syntax syntax );
-
- /** Return a parser for the given syntax */
- public SPARQLParser create ( Syntax syntax );
-}