KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > mem > GraphMemBase


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: GraphMemBase.java,v 1.5 2005/02/21 12:03:45 andy_seaborne Exp $
5 */

6 package com.hp.hpl.jena.mem;
7
8 import com.hp.hpl.jena.graph.impl.GraphBase;
9 import com.hp.hpl.jena.shared.ReificationStyle;
10
11 /**
12      GraphMemBase - a common base class for GraphMem and SmallGraphMem.
13      Any GraphMemBase maintains a reference count, set to one when it is created,
14      and incremented by the method <code>openAgain()</code>. When the graph
15      is closed, the count is decrememented, and when it reaches 0, the tables are
16      trashed and GraphBase.close() called. Thus in normal use one close is enough,
17      but GraphMakers using GraphMems can arrange to re-use the same named
18      graph.
19     
20      @author kers
21 */

22 public abstract class GraphMemBase extends GraphBase
23     {
24     /**
25          The number-of-times-opened count.
26     */

27     protected int count;
28     
29     /**
30          initialise a GraphMemBase withn its count set to 1.
31     */

32     public GraphMemBase( ReificationStyle style )
33         {
34         super( style );
35         count = 1;
36         }
37
38     /**
39          Note a re-opening of this graph by incrementing the count. Answer
40          this Graph.
41     */

42     public GraphMemBase openAgain()
43         {
44         count += 1;
45         return this;
46         }
47
48     /**
49          Sub-classes over-ride this method to release any resources they no
50          longer need once fully closed.
51     */

52     protected abstract void destroy();
53
54     /**
55          Close this graph; if it is now fully closed, destroy its resources and run
56          the GraphBase close.
57     */

58     public void close()
59         {
60         if (--count == 0)
61             {
62             destroy();
63             super.close();
64             }
65         }
66     }
67
68
69 /*
70     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
71     All rights reserved.
72     
73     Redistribution and use in source and binary forms, with or without
74     modification, are permitted provided that the following conditions
75     are met:
76     
77     1. Redistributions of source code must retain the above copyright
78        notice, this list of conditions and the following disclaimer.
79     
80     2. Redistributions in binary form must reproduce the above copyright
81        notice, this list of conditions and the following disclaimer in the
82        documentation and/or other materials provided with the distribution.
83     
84     3. The name of the author may not be used to endorse or promote products
85        derived from this software without specific prior written permission.
86     
87     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 */
Popular Tags