KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2   (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: BaseGraphMaker.java,v 1.13 2005/04/10 12:45:47 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.vocabulary.*;
13
14 /**
15     This base class provides convenience functions for the three "usual" graph
16     makers and a place to hold the reification style for the graphs it constructs.
17  
18     @author kers
19 */

20 public abstract class BaseGraphMaker implements GraphMaker
21     {
22     /**
23         Construct the base level of a graph maker.
24         @param style the reification style for all the graphs it makes
25      */

26     public BaseGraphMaker( ReificationStyle style )
27         { this.style = style; }
28         
29     private int counter = 0;
30     protected ReificationStyle style;
31     
32     /**
33         Answer our reification style.
34     */

35     public ReificationStyle getReificationStyle()
36         { return style; }
37         
38     /**
39         Answer the default graph for this maker. If we haven't already made it, make it
40         now.
41      */

42     public Graph getGraph()
43         {
44         if (defaultGraph == null) defaultGraph = createGraph();
45         return defaultGraph;
46         }
47         
48     private Graph defaultGraph;
49     
50     /**
51         Make a fresh anonymous graph.
52     */

53     public Graph createGraph()
54         { return createGraph( "anon_" + counter++ + "", false ); }
55          
56      /**
57         A non-strict create.
58         @see com.hp.hpl.jena.graph.GraphMaker#createGraph(java.lang.String)
59       */

60     public Graph createGraph(String JavaDoc name)
61         { return createGraph( name, false ); }
62         
63     /**
64         A non-strict open.
65         @see com.hp.hpl.jena.graph.GraphMaker#openGraph(java.lang.String)
66      */

67     public Graph openGraph( String JavaDoc name )
68         { return openGraph( name, false ); }
69
70         
71     /**
72         Answer an RDF specification of this GraphMaker, adequate to constructing one
73         just like it.
74         
75         @return a Graph describing the Maker using the JenaModelSpec vocabulary.
76     */

77     public Graph getDescription()
78         { return getDescription( Node.createAnon() ); }
79         
80     public Graph getDescription( Node root )
81         {
82         Graph result = new GraphMem();
83         addDescription( result, root );
84         return result;
85         }
86                 
87     public Graph addDescription( Graph desc, Node self )
88         {
89         Node mode = JenaModelSpec.styleAsJMS( style );
90         desc.add( Triple.create( self, JenaModelSpec.reificationMode.asNode(), mode ) );
91         desc.add( Triple.create( self, RDF.Nodes.type, getMakerClass() ) );
92         augmentDescription( desc, self );
93         return desc;
94         }
95
96     /**
97         Update the graph g with any other descriptive information for this GraphMaker.
98         @param d the description to be augmented
99         @param self the node that represents this GraphMaker
100     */

101     protected abstract void augmentDescription( Graph d, Node self );
102         
103     /**
104         Answer the Class node for this GraphMaker's description.
105         
106         @return a URI node which is some RDFS subclass of MakerSpec
107     */

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