View Javadoc

1   /*
2    * Copyright James Leigh (c) 2006, 2007.
3    *
4    * Licensed under the Aduna BSD-style license.
5    */
6   package org.openrdf.repository.augur.model;
7   
8   import java.util.Arrays;
9   import java.util.HashMap;
10  import java.util.List;
11  import java.util.Map;
12  
13  import org.openrdf.model.Resource;
14  import org.openrdf.model.URI;
15  import org.openrdf.model.Value;
16  import org.openrdf.query.algebra.TupleExpr;
17  import org.openrdf.repository.RepositoryConnection;
18  
19  /**
20   * Base class for AugurNodes. This class tracks the connection, depth of the
21   * node, the query that was used to create the results, and node that have been
22   * carried over into new requests.
23   * 
24   * @author James Leigh
25   * 
26   */
27  public class AugurNode {
28  
29  	private RepositoryConnection _connection;
30  
31  	private boolean includeInferred;
32  
33  	private int depth = 0;
34  
35  	private TupleExpr _tupleExpr;
36  
37  	private Map<List<Value>, AugurStatementNode> _children = new HashMap<List<Value>, AugurStatementNode>();
38  
39  	public RepositoryConnection getConnection() {
40  		return _connection;
41  	}
42  
43  	public void setConnection(RepositoryConnection connection) {
44  		this._connection = connection;
45  	}
46  
47  	public boolean isIncludeInferred() {
48  		return includeInferred;
49  	}
50  
51  	public void setIncludeInferred(boolean includeInferred) {
52  		this.includeInferred = includeInferred;
53  	}
54  
55  	public int getDepth() {
56  		return depth;
57  	}
58  
59  	public void setDepth(int depth) {
60  		this.depth = depth;
61  	}
62  
63  	public TupleExpr getTupleExpr() {
64  		return _tupleExpr.clone();
65  	}
66  
67  	public void setTupleExpr(TupleExpr tupleExpr) {
68  		this._tupleExpr = tupleExpr;
69  	}
70  
71  	public AugurStatementNode getChildNode(Resource subj, URI pred, Value obj,
72  			Resource... contexts) {
73  		Value[] ar = new Value[3 + contexts.length];
74  		ar[0] = subj;
75  		ar[1] = pred;
76  		ar[2] = obj;
77  		System.arraycopy(contexts, 0, ar, 3, contexts.length);
78  		return _children.get(Arrays.asList(ar));
79  	}
80  
81  	public void addChildNode(AugurStatementNode node, Resource subj, URI pred,
82  			Value obj, Resource... contexts) {
83  		Value[] ar = new Value[3 + contexts.length];
84  		ar[0] = subj;
85  		ar[1] = pred;
86  		ar[2] = obj;
87  		System.arraycopy(contexts, 0, ar, 3, contexts.length);
88  		_children.put(Arrays.asList(ar), node);
89  	}
90  }