1 19 20 package com.hp.hpl.jena.graph.compose; 23 24 25 import com.hp.hpl.jena.graph.*; 28 import com.hp.hpl.jena.graph.impl.WrappedBulkUpdateHandler; 29 import com.hp.hpl.jena.shared.*; 30 import com.hp.hpl.jena.util.iterator.*; 31 32 import java.util.*; 33 34 35 49 public abstract class Polyadic 50 extends CompositionBase 51 { 52 55 56 59 60 63 64 protected List m_subGraphs = new ArrayList(); 65 66 67 protected Graph m_baseGraph = null; 68 69 70 73 78 public Polyadic() { 79 } 80 81 82 89 public Polyadic( Graph[] graphs) { 90 for (int i = 0; i < graphs.length; i++) { 91 m_subGraphs.add( graphs[i] ); 92 } 93 } 94 95 private PrefixMapping pm; 96 97 public PrefixMapping getPrefixMapping() 98 { 99 if (pm == null) pm = new PolyadicPrefixMappingImpl( this ); 100 return pm; 101 } 102 103 111 public Polyadic( Iterator graphs ) { 112 while (graphs.hasNext()) { 113 m_subGraphs.add( graphs.next() ); 114 } 115 116 if (graphs instanceof ClosableIterator) { 117 ((ClosableIterator) graphs).close(); 118 } 119 } 120 121 122 125 132 public void close() { 133 for (Iterator i = m_subGraphs.iterator(); i.hasNext(); ) { 134 ((Graph) i.next()).close(); 135 } 136 } 137 138 139 148 public boolean dependsOn( Graph graph ) { 149 return (graph == this) || m_subGraphs.contains( graph ); 150 } 151 152 153 160 public void addGraph( Graph graph ) { 161 m_subGraphs.add( graph ); 162 } 163 164 165 174 public void removeGraph( Graph graph ) { 175 m_subGraphs.remove( graph ); 176 177 if (m_baseGraph == graph) { 178 m_baseGraph = null; 179 } 180 } 181 182 183 192 public Graph getBaseGraph() { 193 if (m_baseGraph == null) { 194 return (m_subGraphs.size() == 0) ? null : ((Graph) m_subGraphs.get( 0 )); 196 } 197 else { 198 return m_baseGraph; 199 } 200 } 201 202 203 213 public void setBaseGraph( Graph graph ) { 214 if (m_subGraphs.contains( graph )) { 215 m_baseGraph = graph; 216 bulkHandler = null; 217 } 218 else { 219 throw new IllegalArgumentException ( "The updateable graph must be one of the graphs from the composition" ); 220 } 221 } 222 223 224 231 public List getSubGraphs() { 232 List sg = new ArrayList( m_subGraphs ); 233 234 if (getBaseGraph() != null) { 235 sg.remove( getBaseGraph() ); 236 } 237 238 return sg; 239 } 240 241 public BulkUpdateHandler getBulkUpdateHandler() { 242 if (getBaseGraph() == null) 243 throw new RuntimeException (); if (bulkHandler == null) 245 bulkHandler = new WrappedBulkUpdateHandler( this, getBaseGraph().getBulkUpdateHandler() ); 246 return bulkHandler; 247 } 248 249 252 public TransactionHandler getTransactionHandler() { 253 return (getBaseGraph() == null) ? super.getTransactionHandler() : getBaseGraph().getTransactionHandler(); 254 } 255 256 public Capabilities getCapabilities() { 257 return (getBaseGraph() == null) ? super.getCapabilities() : getBaseGraph().getCapabilities(); 258 } 259 260 } 261 262 263 292 293 | Popular Tags |