1 6 7 package com.hp.hpl.jena.db.impl; 8 9 import com.hp.hpl.jena.db.*; 10 11 16 17 import java.util.List ; 18 19 import com.hp.hpl.jena.graph.*; 20 import com.hp.hpl.jena.util.iterator.*; 21 import com.hp.hpl.jena.shared.*; 22 23 public class DBReifier implements Reifier 24 { 25 protected GraphRDB m_parent = null; 26 protected Graph m_hiddenTriples = null; 27 protected List m_reifiers = null; 28 protected List m_hidden_reifiers = null; 29 30 protected SpecializedGraphReifier m_reifier = null; 35 36 protected ReificationStyle m_style; 37 38 45 public DBReifier(GraphRDB parent, ReificationStyle style, List allReifiers, List hiddenReifiers ) { 46 m_parent = parent; 47 m_reifiers = allReifiers; 48 m_hidden_reifiers = hiddenReifiers; 49 m_style = style; 50 51 if (m_reifiers.size() != 1) 53 throw new BrokenException("Internal error - DBReifier requires exactly one SpecializedGraphReifier"); 54 m_reifier = (SpecializedGraphReifier) m_reifiers.get(0); 55 } 56 57 60 public Graph getParentGraph() { 61 return m_parent; } 62 63 public ReificationStyle getStyle() 64 { return m_style; } 65 66 69 private Graph getReificationTriples() { 70 if( m_hiddenTriples == null) 71 m_hiddenTriples = new DBReifierGraph(m_parent, m_hidden_reifiers); 72 return m_hiddenTriples; 73 } 74 75 public ExtendedIterator find( TripleMatch m ) 76 { return getReificationTriples().find( m ); } 77 78 public ExtendedIterator findExposed( TripleMatch m ) 79 { return getReificationTriples().find( m ); } 80 81 public ExtendedIterator findEither( TripleMatch m, boolean showHidden ) 82 { return showHidden == m_style.conceals() ? getReificationTriples().find( m ) : NullIterator.instance; } 83 84 public int size() 85 { return m_style.conceals() ? 0 : getReificationTriples().size(); } 86 87 91 protected static SpecializedGraph.CompletionFlag newComplete() 92 { return new SpecializedGraph.CompletionFlag(); } 93 94 97 public Node reifyAs( Node n, Triple t ) { 98 m_reifier.add( n, t, newComplete() ); 99 return n; 100 } 101 102 105 public boolean hasTriple(Node n) { 106 return m_reifier.findReifiedTriple( n, newComplete() ) != null; 107 } 108 109 112 public boolean hasTriple( Triple t ) { 113 return m_reifier.findReifiedNodes(t, newComplete() ).hasNext(); 114 } 115 116 119 public ExtendedIterator allNodes() { 120 return m_reifier.findReifiedNodes( null, newComplete() ); 121 } 122 123 127 public ExtendedIterator allNodes( Triple t ) 128 { return m_reifier.findReifiedNodes( t, newComplete() ); } 129 130 133 public void remove( Node n, Triple t ) { 134 m_reifier.delete( n, t, newComplete() ); 135 } 136 137 140 public void remove( Triple t ) { 141 m_reifier.delete(null,t, newComplete() ); 142 } 143 144 147 public boolean handledAdd(Triple t) { 148 SpecializedGraph.CompletionFlag complete = newComplete(); 149 m_reifier.add(t, complete); 150 return complete.isDone(); 151 } 152 153 156 public boolean handledRemove(Triple t) { 157 SpecializedGraph.CompletionFlag complete = newComplete(); 158 m_reifier.delete(t, complete); 159 return complete.isDone(); 160 } 161 162 165 public Triple getTriple(Node n) { 166 return m_reifier.findReifiedTriple(n, newComplete() ); 167 } 168 169 public void close() { 170 } 172 173 } 174 175 204 | Popular Tags |