KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > impl > SimpleGraphMaker


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: SimpleGraphMaker.java,v 1.13 2005/04/10 12:45:48 chris-dollin Exp $
5 */

6
7 package com.hp.hpl.jena.graph.impl;
8
9 import com.hp.hpl.jena.graph.*;
10 import com.hp.hpl.jena.mem.*;
11 import com.hp.hpl.jena.shared.*;
12 import com.hp.hpl.jena.util.iterator.*;
13 import com.hp.hpl.jena.vocabulary.*;
14
15 import java.util.*;
16
17 /**
18     @author hedgehog
19     
20     A SimpleGraphFactory produces memory-based graphs and records them
21     in a local map.
22 */

23
24 public class SimpleGraphMaker extends BaseGraphMaker
25     {
26     /**
27         Initialise a SimpleGraphMaker with the given style.
28         @param style the reification style of all the graphs we create
29     */

30     public SimpleGraphMaker( ReificationStyle style )
31         { super( style ); }
32        
33     /**
34         Initialise a SimpleGraphMaker with reification style Minimal
35     */

36     public SimpleGraphMaker()
37         { this( ReificationStyle.Minimal ); }
38        
39     /**
40         Answer the RDFS class of this Maker
41         @return JenaModelSpec.MemMakerClass [as node]
42     */

43     public Node getMakerClass()
44         { return JenaModelSpec.MemMakerSpec.asNode(); }
45        
46     /**
47         Augment the general description of a GraphMaker with any Simple triples [ie none]
48     */

49     protected void augmentDescription( Graph d, Node self )
50         {}
51     
52     /**
53         The mapping from the names of graphs to the Graphs themselves.
54     */

55     private Map graphs = new HashMap();
56     
57     public Graph create()
58         { return new GraphMem(); }
59     
60     /**
61         Create a graph and record it with the given name in the local map.
62      */

63     public Graph createGraph( String JavaDoc name, boolean strict )
64         {
65         GraphMem already = (GraphMem) graphs.get( name );
66         if (already == null)
67             {
68             Graph result = new GraphMem( style );
69             graphs.put( name, result );
70             return result;
71             }
72         else if (strict)
73             throw new AlreadyExistsException( name );
74         else
75             return already.openAgain();
76         }
77         
78     /**
79         Open (aka find) a graph with the given name in the local map.
80      */

81     public Graph openGraph( String JavaDoc name, boolean strict )
82         {
83         GraphMem already = (GraphMem) graphs.get( name );
84         if (already == null)
85             if (strict) throw new DoesNotExistException( name );
86             else return createGraph( name, true );
87         else
88             return already.openAgain();
89         }
90         
91     /**
92         Remove the mapping from name to any graph from the local map.
93      */

94     public void removeGraph( String JavaDoc name )
95         {
96         if (!graphs.containsKey( name )) throw new DoesNotExistException( name );
97         graphs.remove( name );
98         }
99         
100     /**
101         Return true iff we have a graph with the given name
102     */

103     public boolean hasGraph( String JavaDoc name )
104         { return graphs.containsKey( name ); }
105              
106     /**
107         Close this factory - we choose to do nothing.
108      */

109     public void close()
110         { /* nothing to do */ }
111         
112     public ExtendedIterator listGraphs()
113         { return WrappedIterator.create( graphs.keySet().iterator() ); }
114     }
115
116
117 /*
118     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
119     All rights reserved.
120
121     Redistribution and use in source and binary forms, with or without
122     modification, are permitted provided that the following conditions
123     are met:
124
125     1. Redistributions of source code must retain the above copyright
126        notice, this list of conditions and the following disclaimer.
127
128     2. Redistributions in binary form must reproduce the above copyright
129        notice, this list of conditions and the following disclaimer in the
130        documentation and/or other materials provided with the distribution.
131
132     3. The name of the author may not be used to endorse or promote products
133        derived from this software without specific prior written permission.
134
135     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
136     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
137     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
138     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
139     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
140     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
144     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145 */
Popular Tags