⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphbase.java

📁 Jena推理机
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
  (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
  [See end of file]
  $Id: GraphBase.java,v 1.47 2007/01/12 15:01:33 chris-dollin Exp $
*/

package com.hp.hpl.jena.graph.impl;

import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.graph.query.*;
import com.hp.hpl.jena.util.iterator.*;

import com.hp.hpl.jena.shared.*;
import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;

/**
    GraphBase is an implementation of Graph that provides some convenient
    base functionality for Graph implementations.
<p>
    Subtypes of GraphBase must provide performAdd(Triple), performDelete(Triple), 
    graphBaseFind(TripleMatch,TripleAction), and graphBaseSize(). GraphBase 
    provides default implementations of the other methods, including the other finds 
    (on top of that one), a simple-minded prepare, and contains. GraphBase also 
    handles the event-listening and registration interfaces.
<p>
    When a GraphBase is closed, future operations on it may throw an exception.
    
	@author kers
*/

public abstract class GraphBase implements GraphWithPerform 
	{
    /**
         The reification style of this graph, used when the reifier is created (and
         nowhere else, as it happens, which is good).
    */
    protected final ReificationStyle style;
    
    /**
         Whether or not this graph has been closed - used to report ClosedExceptions
         when an operation is attempted on a closed graph.
    */
    protected boolean closed = false;

    /**
         Initialise this graph as one with reification style Minimal.
    */
    public GraphBase()
        { this( ReificationStyle.Minimal ); }
    
    /**
         Initialise this graph with the given reification style (which will be supplied to
         the reifier when it is created).
    */
    public GraphBase( ReificationStyle style )
        { this.style = style; }
        
    /**
         Utility method: throw a ClosedException if this graph has been closed.
    */
    protected void checkOpen()
        { if (closed) throw new ClosedException( "already closed", this ); }

    /**
         Close this graph. Subgraphs may extend to discard resources.
    */
    public void close() 
        { 
        closed = true;
        if (reifier != null) reifier.close(); 
        }
    
    public boolean isClosed()
        { return closed; }
            
    /**
         Default implemenentation answers <code>true</code> iff this graph is the
         same graph as the argument graph.
    */
	public boolean dependsOn( Graph other ) 
        { return this == other; }

	/**
		Answer a QueryHandler bound to this graph. The default implementation
        returns the same SimpleQueryHandler each time it is called; sub-classes
        may override if they need specialised query handlers.
	*/
	public QueryHandler queryHandler() 
        { 
        if (queryHandler == null) queryHandler = new SimpleQueryHandler(this);
        return queryHandler;
        }
    
    /**
         The query handler for this graph, or null if queryHandler() has not been
         called yet. 
    */
    protected QueryHandler queryHandler;
    
    /**
        Answer the event manager for this graph; allocate a new one if required.
        Subclasses may override if they have a more specialed event handler.
        The default is a SimpleEventManager.
    */
    public GraphEventManager getEventManager()
        { 
        if (gem == null) gem = new SimpleEventManager( this ); 
        return gem;
        }
    
    /**
        The event manager that this Graph uses to, well, manage events; allocated on
        demand.
    */
    protected GraphEventManager gem;

        
    /**
        Tell the event manager that the triple <code>t</code> has been added to the graph.
    */
    public void notifyAdd( Triple t )
        { getEventManager().notifyAddTriple( this, t ); }
        
    /**
        Tell the event manager that the triple <code>t</code> has been deleted from the
        graph.
    */
    public void notifyDelete( Triple t )
        { getEventManager().notifyDeleteTriple( this, t ); }
        
    /**
         Answer a transaction handler bound to this graph. The default is
         SimpleTransactionHandler, which handles <i>no</i> transactions.
    */
    public TransactionHandler getTransactionHandler()
        { return new SimpleTransactionHandler(); }
        
    /**
         Answer a BulkUpdateHandler bound to this graph. The default is a
         SimpleBulkUpdateHandler, which does bulk update by repeated simple
         (add/delete) updates; the same handler is returned on each call. Subclasses
         may override if they have specialised implementations.
    */
    public BulkUpdateHandler getBulkUpdateHandler()
        { 
        if (bulkHandler == null) bulkHandler = new SimpleBulkUpdateHandler( this ); 
        return bulkHandler;
        }

    /**
         The allocated BulkUpdateHandler, or null if no handler has been allocated yet.
    */
    protected BulkUpdateHandler bulkHandler;
    
    /**
         Answer the capabilities of this graph; the default is an AllCapabilities object
         (the same one each time, not that it matters - Capabilities should be 
         immutable).
    */
    public Capabilities getCapabilities()
        { 
        if (capabilities == null) capabilities = new AllCapabilities();
        return capabilities;
        }

    /**
         The allocated Capabilities object, or null if unallocated.
    */
    protected Capabilities capabilities = null;
    
    /**
         Answer the PrefixMapping object for this graph, the same one each time.
         Subclasses are unlikely to want to modify this.
    */
    public PrefixMapping getPrefixMapping()
        { return pm; }

    protected PrefixMapping pm = new PrefixMappingImpl();
    
	/**
	   Add a triple, and notify the event manager. Subclasses should not need to
       override this - we might make it final. The triple is added using performAdd,
       and notification done by notifyAdd.
	*/
	public void add( Triple t ) 
        {
        checkOpen();
        performAdd( t );
        notifyAdd( t );
        }
    
    /**
         Add a triple to the triple store. The default implementation throws an
         AddDeniedException; subclasses must override if they want to be able to
         add triples.
    */
    public void performAdd( Triple t )
        { throw new AddDeniedException( "GraphBase::performAdd" ); }

	/**
       Delete a triple, and notify the event manager. Subclasses should not need to
       override this - we might make it final. The triple is added using performDelete,
       and notification done by notifyDelete.
	 */
    
    public final void delete( Triple t )
        {
        checkOpen();
        performDelete( t );
        notifyDelete( t );
        }
        
    /**
         Remove a triple from the triple store. The default implementation throws
         a DeleteDeniedException; subclasses must override if they want to be able
         to remove triples.
    */
	public void performDelete( Triple t ) 
        { throw new DeleteDeniedException( "GraphBase::delete" ); }

	/**
	     Answer an (extended) iterator over all the triples in this Graph matching
         <code>m</code>. Subclasses cannot over-ride this, because it implements
         the appending of reification quadlets; instead they must implement
         graphBaseFind(TripleMatch).
	*/
	public final ExtendedIterator find( TripleMatch m )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -