001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: ModelListenerAdapter.java,v 1.20 2008/01/02 12:05:00 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.impl;
008:
009: import com.hp.hpl.jena.graph.*;
010: import com.hp.hpl.jena.rdf.model.*;
011:
012: import java.util.*;
013:
014: /**
015: Adapter class that converts a ModelChangedListener into a GraphListener.
016: The only tricky bit is that we have to implement equality as equality of the
017: underlying ModelChangedListeners/ModelCom pairs.
018: <p>
019: This implementation only works for <code>ModelCom</code> models,
020: because it relies on various service methods; this gives the model the
021: opportunity to cache various mappings for efficiency.
022:
023: @author hedgehog
024: */
025: public class ModelListenerAdapter implements GraphListener {
026: protected ModelCom m;
027: protected ModelChangedListener L;
028:
029: public ModelListenerAdapter(ModelCom m, ModelChangedListener L) {
030: this .m = m;
031: this .L = L;
032: }
033:
034: public void notifyAddArray(Graph graph, Triple[] triples) {
035: L.addedStatements(m.asStatements(triples));
036: }
037:
038: public void notifyDeleteArray(Graph g, Triple[] triples) {
039: L.removedStatements(m.asStatements(triples));
040: }
041:
042: public void notifyAddTriple(Graph g, Triple t) {
043: L.addedStatement(m.asStatement(t));
044: }
045:
046: public void notifyAddList(Graph g, List triples) {
047: L.addedStatements(m.asStatements(triples));
048: }
049:
050: public void notifyAddIterator(Graph g, Iterator it) {
051: L.addedStatements(m.asStatements(it));
052: }
053:
054: public void notifyAddGraph(Graph g, Graph added) {
055: L.addedStatements(m.asModel(added));
056: }
057:
058: public void notifyDeleteIterator(Graph g, Iterator it) {
059: L.removedStatements(m.asStatements(it));
060: }
061:
062: public void notifyDeleteTriple(Graph g, Triple t) {
063: L.removedStatement(m.asStatement(t));
064: }
065:
066: public void notifyAddIterator(Graph g, List triples) {
067: L.addedStatements(m.asStatements(triples));
068: }
069:
070: public void notifyDeleteList(Graph g, List triples) {
071: L.removedStatements(m.asStatements(triples));
072: }
073:
074: public void notifyDeleteGraph(Graph g, Graph removed) {
075: L.removedStatements(m.asModel(removed));
076: }
077:
078: public void notifyEvent(Graph g, Object event) {
079: L.notifyEvent(m, event);
080: }
081:
082: public boolean equals(Object other) {
083: return other instanceof ModelListenerAdapter
084: && ((ModelListenerAdapter) other).sameAs(this );
085: }
086:
087: public boolean sameAs(ModelListenerAdapter other) {
088: return this .L.equals(other.L) && this .m.equals(other.m);
089: }
090: }
091:
092: /*
093: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
094: All rights reserved.
095:
096: Redistribution and use in source and binary forms, with or without
097: modification, are permitted provided that the following conditions
098: are met:
099:
100: 1. Redistributions of source code must retain the above copyright
101: notice, this list of conditions and the following disclaimer.
102:
103: 2. Redistributions in binary form must reproduce the above copyright
104: notice, this list of conditions and the following disclaimer in the
105: documentation and/or other materials provided with the distribution.
106:
107: 3. The name of the author may not be used to endorse or promote products
108: derived from this software without specific prior written permission.
109:
110: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
111: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
112: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
113: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
114: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
115: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
116: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
117: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
118: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
119: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
120: */
|