KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > model > impl > ModelListenerAdapter


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: ModelListenerAdapter.java,v 1.17 2005/02/21 12:14:34 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.rdf.model.impl;
8
9 import com.hp.hpl.jena.graph.*;
10 import com.hp.hpl.jena.rdf.model.*;
11
12 import java.util.*;
13
14 /**
15     Adapter class that converts a ModelChangedListener into a GraphListener.
16     The only tricky bit is that we have to implement equality as equality of the
17     underlying ModelChangedListeners/ModelCom pairs.
18 <p>
19     This implementation only works for <code>ModelCom</code> models,
20     because it relies on various service methods; this gives the model the
21     opportunity to cache various mappings for efficiency.
22     
23     @author hedgehog
24 */

25 public class ModelListenerAdapter implements GraphListener
26     {
27     protected ModelCom m;
28     protected ModelChangedListener L;
29
30     public ModelListenerAdapter( ModelCom m, ModelChangedListener L )
31         { this.m = m; this.L = L; }
32
33     public void notifyAddArray( Graph graph, Triple [] triples )
34         { L.addedStatements( m.asStatements( triples ) ); }
35         
36     public void notifyDeleteArray( Graph g, Triple [] triples )
37         { L.removedStatements( m.asStatements( triples ) ); }
38         
39     public void notifyAddTriple( Graph g, Triple t )
40         { L.addedStatement( m.asStatement( t ) ); }
41
42     public void notifyAddList( Graph g, List triples )
43         { L.addedStatements( m.asStatements( triples ) ); }
44               
45     public void notifyAddIterator( Graph g, Iterator it )
46         { L.addedStatements( m.asStatements( it ) ); }
47         
48     public void notifyAddGraph( Graph g, Graph added )
49         { L.addedStatements( m.asModel( added ) ); }
50         
51     public void notifyDeleteIterator( Graph g, Iterator it )
52         { L.removedStatements( m.asStatements( it ) ); }
53         
54     public void notifyDeleteTriple( Graph g, Triple t )
55         { L.removedStatement( m.asStatement( t ) ); }
56         
57     public void notifyAddIterator( Graph g, List triples )
58         { L.addedStatements( m.asStatements( triples ) ); }
59         
60     public void notifyDeleteList( Graph g, List triples )
61         { L.removedStatements( m.asStatements( triples ) ); }
62
63     public void notifyDeleteGraph( Graph g, Graph removed )
64         { L.removedStatements( m.asModel( removed ) ); }
65     
66     public void notifyEvent( Graph g, Object JavaDoc event )
67         { L.notifyEvent( m, event ); }
68         
69     public boolean equals( Object JavaDoc other )
70         {
71         return
72             other instanceof ModelListenerAdapter
73             && ((ModelListenerAdapter) other).sameAs( this )
74             ;
75         }
76         
77     public boolean sameAs( ModelListenerAdapter other )
78         { return this.L.equals( other.L ) && this.m.equals( other.m ); }
79     }
80
81 /*
82     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
83     All rights reserved.
84
85     Redistribution and use in source and binary forms, with or without
86     modification, are permitted provided that the following conditions
87     are met:
88
89     1. Redistributions of source code must retain the above copyright
90        notice, this list of conditions and the following disclaimer.
91
92     2. Redistributions in binary form must reproduce the above copyright
93        notice, this list of conditions and the following disclaimer in the
94        documentation and/or other materials provided with the distribution.
95
96     3. The name of the author may not be used to endorse or promote products
97        derived from this software without specific prior written permission.
98
99     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
100     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
101     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
102     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
103     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
104     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
105     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
106     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
107     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
108     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109 */

110
Popular Tags