KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > db > impl > DBReifierGraph


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4 */

5
6 package com.hp.hpl.jena.db.impl;
7
8 import com.hp.hpl.jena.db.GraphRDB;
9 import com.hp.hpl.jena.graph.*;
10 import com.hp.hpl.jena.graph.impl.*;
11 import com.hp.hpl.jena.graph.query.*;
12 import com.hp.hpl.jena.shared.*;
13 import com.hp.hpl.jena.util.iterator.*;
14
15 import java.util.*;
16
17 /**
18  *
19  * Implementation of a "hidden triples" graph for reified statements in GraphRDB.
20  *
21  * This makes the list of specializedGraphReifers in the GraphRDB into a read-only
22  * Graph - suitable to be returned by Reifier.getHiddenTriples() )
23  *
24  * @since Jena 2.0
25  *
26  * @author csayers
27  * @version $Revision: 1.18 $
28  */

29 public class DBReifierGraph implements Graph {
30
31     protected List m_specializedGraphs = null; // list of SpecializedGraphReifiers
32
protected GraphRDB m_parent = null; // parent graph;
33

34     /**
35      * Construct a new DBReifierGraph
36      *
37      * @param reifiers List of SpecializedGraphReifers which holds the reified triples. This
38      * list may be empty and, in that case, the DBReifierGraph just appears to hold no triples.
39      */

40     public DBReifierGraph( GraphRDB parent, List reifiers) {
41     
42         m_parent = parent;
43         m_specializedGraphs = reifiers;
44         
45     }
46     
47     /* (non-Javadoc)
48      * @see com.hp.hpl.jena.graph.Graph#add(com.hp.hpl.jena.graph.Triple)
49      */

50     public void add( Triple t ) {
51         throw new AddDeniedException( "cannot add to DB reifier", t );
52     }
53
54     /* (non-Javadoc)
55      * @see com.hp.hpl.jena.graph.Graph#delete(com.hp.hpl.jena.graph.Triple)
56      */

57     public void delete(Triple t) {
58         throw new DeleteDeniedException( "cannot delete from a DB reifier", t );
59     }
60
61     /* (non-Javadoc)
62      * @see com.hp.hpl.jena.graph.Graph#size()
63      */

64     public int size() {
65         checkUnclosed();
66         int result =0;
67         Iterator it = m_specializedGraphs.iterator();
68         while( it.hasNext() ) {
69             SpecializedGraph sg = (SpecializedGraph) it.next();
70             result += sg.tripleCount();
71         }
72         return result;
73     }
74
75     public boolean isEmpty()
76         { return size() == 0; }
77         
78     private void checkUnclosed()
79         {
80         if (m_specializedGraphs == null)
81             throw new ClosedException( "this DB Reifier has been closed", this );
82         }
83         
84     /* (non-Javadoc)
85      * @see com.hp.hpl.jena.graph.Graph#contains(com.hp.hpl.jena.graph.Triple)
86      */

87     public boolean contains(Triple t) {
88         checkUnclosed();
89         SpecializedGraph.CompletionFlag complete = newComplete();
90         Iterator it = m_specializedGraphs.iterator();
91         while( it.hasNext() ) {
92             SpecializedGraph sg = (SpecializedGraph) it.next();
93             boolean result = sg.contains( t, newComplete() );
94             if (result || complete.isDone()) return result;
95         }
96         return false;
97     }
98     
99     protected SpecializedGraph.CompletionFlag newComplete()
100         { return new SpecializedGraph.CompletionFlag(); }
101
102     /* (non-Javadoc)
103      * @see com.hp.hpl.jena.graph.Graph#contains(com.hp.hpl.jena.graph.Node, com.hp.hpl.jena.graph.Node, com.hp.hpl.jena.graph.Node)
104      */

105     public boolean contains(Node s, Node p, Node o) {
106         return contains( Triple.create( s, p, o ) );
107     }
108             
109
110     /* (non-Javadoc)
111      * @see com.hp.hpl.jena.graph.Graph#find(com.hp.hpl.jena.graph.TripleMatch)
112      */

113     public ExtendedIterator find(TripleMatch m) {
114         checkUnclosed();
115         ExtendedIterator result = new NiceIterator();
116         SpecializedGraph.CompletionFlag complete = newComplete();
117         Iterator it = m_specializedGraphs.iterator();
118         while( it.hasNext() ) {
119             SpecializedGraph sg = (SpecializedGraph) it.next();
120             ExtendedIterator partialResult = sg.find( m, complete);
121             result = result.andThen(partialResult);
122             if( complete.isDone())
123                 break;
124         }
125         return result;
126     }
127
128     /* (non-Javadoc)
129      * @see com.hp.hpl.jena.graph.Graph#getPrefixMapping()
130      */

131     public PrefixMapping getPrefixMapping() {
132         return m_parent.getPrefixMapping();
133     }
134
135
136     /* (non-Javadoc)
137      * @see com.hp.hpl.jena.graph.Graph#getTransactionHandler()
138      */

139     public TransactionHandler getTransactionHandler() {
140         return m_parent.getTransactionHandler();
141     }
142
143     /* (non-Javadoc)
144      * @see com.hp.hpl.jena.graph.Graph#close()
145      */

146     public void close() {
147         m_specializedGraphs = null;
148         m_parent = null;
149     }
150     
151     public GraphEventManager getEventManager()
152         { throw new BrokenException( "DB reifiers do not yet implement getEventManager" ); }
153     
154     /* (non-Javadoc)
155      * @see com.hp.hpl.jena.graph.Graph#dependsOn(com.hp.hpl.jena.graph.Graph)
156      */

157     public boolean dependsOn(Graph other) {
158         return m_parent.dependsOn(other);
159     }
160
161     /* (non-Javadoc)
162      * @see com.hp.hpl.jena.graph.Graph#queryHandler()
163      */

164     public QueryHandler queryHandler() {
165         return new SimpleQueryHandler(this);
166     }
167
168     /* (non-Javadoc)
169      * @see com.hp.hpl.jena.graph.Graph#getBulkUpdateHandler()
170      */

171     public BulkUpdateHandler getBulkUpdateHandler() {
172         return m_parent.getBulkUpdateHandler();
173     }
174
175     /* (non-Javadoc)
176      * @see com.hp.hpl.jena.graph.Graph#getCapabilities()
177      */

178     public Capabilities getCapabilities() {
179         return null;
180     }
181
182     /* (non-Javadoc)
183      * @see com.hp.hpl.jena.graph.Graph#getReifier()
184      */

185     public Reifier getReifier() {
186         throw new JenaException( "DB Reifier graphs have no reifiers" );
187     }
188
189     /* (non-Javadoc)
190      * @see com.hp.hpl.jena.graph.Graph#find(com.hp.hpl.jena.graph.Node, com.hp.hpl.jena.graph.Node, com.hp.hpl.jena.graph.Node)
191      */

192     public ExtendedIterator find(Node s, Node p, Node o) {
193         return find( Triple.createMatch( s, p, o ) );
194     }
195
196     /* (non-Javadoc)
197      * @see com.hp.hpl.jena.graph.Graph#isIsomorphicWith(com.hp.hpl.jena.graph.Graph)
198      */

199     public boolean isIsomorphicWith(Graph g) {
200         return g != null && GraphMatcher.equals( this, g );
201     }
202
203     /* (non-Javadoc)
204      * @see com.hp.hpl.jena.graph.Graph#capabilities()
205      */

206     public int capabilities() {
207         return 0;
208     }
209     
210     public String JavaDoc toString()
211         { return GraphBase.toString( "DBReifier ", this ); }
212 }
213
214 /*
215  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
216  * All rights reserved.
217  *
218  * Redistribution and use in source and binary forms, with or without
219  * modification, are permitted provided that the following conditions
220  * are met:
221  * 1. Redistributions of source code must retain the above copyright
222  * notice, this list of conditions and the following disclaimer.
223  * 2. Redistributions in binary form must reproduce the above copyright
224  * notice, this list of conditions and the following disclaimer in the
225  * documentation and/or other materials provided with the distribution.
226  * 3. The name of the author may not be used to endorse or promote products
227  * derived from this software without specific prior written permission.
228
229  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
230  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
231  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
232  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
233  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
234  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
235  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
236  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
237  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
238  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
239  */
Popular Tags