001: /******************************************************************
002: * File: MonitorModel.java
003: * Created by: Dave Reynolds
004: * Created on: 12-May-2005
005: *
006: * (c) Copyright 2005, Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: MonitorModel.java,v 1.4 2008/01/02 12:07:44 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.util;
010:
011: import java.util.*;
012:
013: import com.hp.hpl.jena.graph.Triple;
014: import com.hp.hpl.jena.rdf.model.Model;
015: import com.hp.hpl.jena.rdf.model.impl.ModelCom;
016:
017: /**
018: * Model wrapper which provides normal access to an underlying model but
019: * also maintains a snapshot of the triples it was last known to contain.
020: * A snapshot action
021: * causes the set of changes between this and the previous snapshot to
022: * be calculated and the cache updated. The snapshot process will also
023: * fire change notification.
024: *
025: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
026: * @version $Revision: 1.4 $
027: */
028:
029: public class MonitorModel extends ModelCom {
030:
031: /**
032: * Create a monitor over the given underlying base model.
033: */
034: public MonitorModel(Model base) {
035: super (new MonitorGraph(base.getGraph()));
036: }
037:
038: /**
039: * Compute the differences between the current monitored graph and the last
040: * snapshot. The changes will also be forwarded to any listeners.
041: * Then take a new snapshot.
042: * @param additions a place in which the set of newly added statements should be noted, can be null
043: * @param deletions a place in which the set of newly deleted statements should be noted, can be null
044: */
045: public void snapshot(List additions, List deletions) {
046: List additionsTemp = (additions != null) ? new ArrayList()
047: : null;
048: List deletionsTemp = (deletions != null) ? new ArrayList()
049: : null;
050: ((MonitorGraph) getGraph()).snapshot(additionsTemp,
051: deletionsTemp);
052: if (additions != null) {
053: for (Iterator i = additionsTemp.iterator(); i.hasNext();) {
054: additions.add(this .asStatement((Triple) i.next()));
055: }
056: }
057: if (deletions != null) {
058: for (Iterator i = deletionsTemp.iterator(); i.hasNext();) {
059: deletions.add(this .asStatement((Triple) i.next()));
060: }
061: }
062: }
063:
064: /**
065: * Compute the differences between the current monitored graph and the last
066: * snapshot, forward any changes to registered listeners, then take a new snapshot.
067: */
068: public void snapshot() {
069: snapshot(null, null);
070: }
071:
072: }
073:
074: /*
075: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
076: All rights reserved.
077:
078: Redistribution and use in source and binary forms, with or without
079: modification, are permitted provided that the following conditions
080: are met:
081:
082: 1. Redistributions of source code must retain the above copyright
083: notice, this list of conditions and the following disclaimer.
084:
085: 2. Redistributions in binary form must reproduce the above copyright
086: notice, this list of conditions and the following disclaimer in the
087: documentation and/or other materials provided with the distribution.
088:
089: 3. The name of the author may not be used to endorse or promote products
090: derived from this software without specific prior written permission.
091:
092: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
093: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
094: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
095: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
096: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
097: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
098: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
099: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
100: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
101: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
102: */
|