001: /*
002: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: BaseGraphMaker.java,v 1.19 2008/01/02 12:05:20 andy_seaborne Exp $
005: */
006:
007: package com.hp.hpl.jena.graph.impl;
008:
009: import com.hp.hpl.jena.graph.*;
010: import com.hp.hpl.jena.shared.*;
011: import com.hp.hpl.jena.vocabulary.*;
012:
013: /**
014: This base class provides convenience functions for the three "usual" graph
015: makers and a place to hold the reification style for the graphs it constructs.
016:
017: @author kers
018: */
019: public abstract class BaseGraphMaker implements GraphMaker {
020: /**
021: Construct the base level of a graph maker.
022: @param style the reification style for all the graphs it makes
023: */
024: public BaseGraphMaker(ReificationStyle style) {
025: this .style = style;
026: }
027:
028: private int counter = 0;
029: protected ReificationStyle style;
030:
031: /**
032: Answer our reification style.
033: */
034: public ReificationStyle getReificationStyle() {
035: return style;
036: }
037:
038: /**
039: Answer the default graph for this maker. If we haven't already made it, make it
040: now.
041: */
042: public Graph getGraph() {
043: if (defaultGraph == null) {
044: defaultGraph = createGraph();
045: }
046: return defaultGraph;
047: }
048:
049: private Graph defaultGraph;
050:
051: public Graph openGraph() {
052: if (defaultGraph == null)
053: throw new DoesNotExistException(
054: "no default graph in this GraphMaker ["
055: + this .getClass() + "]");
056: return defaultGraph;
057: }
058:
059: /**
060: Make a fresh anonymous graph.
061: */
062: public Graph createGraph() {
063: return createGraph("anon_" + counter++ + "", false);
064: }
065:
066: /**
067: A non-strict create.
068: @see com.hp.hpl.jena.graph.GraphMaker#createGraph(java.lang.String)
069: */
070: public Graph createGraph(String name) {
071: return createGraph(name, false);
072: }
073:
074: /**
075: A non-strict open.
076: @see com.hp.hpl.jena.graph.GraphMaker#openGraph(java.lang.String)
077: */
078: public Graph openGraph(String name) {
079: return openGraph(name, false);
080: }
081:
082: /**
083: Answer an RDF specification of this GraphMaker, adequate to constructing one
084: just like it.
085:
086: @return a Graph describing the Maker using the JenaModelSpec vocabulary.
087: */
088: public Graph getDescription() {
089: return getDescription(Node.createAnon());
090: }
091:
092: public Graph getDescription(Node root) {
093: Graph result = Factory.createGraphMem();
094: addDescription(result, root);
095: return result;
096: }
097:
098: public Graph addDescription(Graph desc, Node self) {
099: Node mode = JenaModelSpec.styleAsJMS(style);
100: desc.add(Triple.create(self, JenaModelSpec.reificationMode
101: .asNode(), mode));
102: desc.add(Triple.create(self, RDF.Nodes.type, getMakerClass()));
103: augmentDescription(desc, self);
104: return desc;
105: }
106:
107: /**
108: Update the graph g with any other descriptive information for this GraphMaker.
109: @param d the description to be augmented
110: @param self the node that represents this GraphMaker
111: */
112: protected abstract void augmentDescription(Graph d, Node self);
113:
114: /**
115: Answer the Class node for this GraphMaker's description.
116:
117: @return a URI node which is some RDFS subclass of MakerSpec
118: */
119: public abstract Node getMakerClass();
120: }
121:
122: /*
123: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
124: All rights reserved.
125:
126: Redistribution and use in source and binary forms, with or without
127: modification, are permitted provided that the following conditions
128: are met:
129:
130: 1. Redistributions of source code must retain the above copyright
131: notice, this list of conditions and the following disclaimer.
132:
133: 2. Redistributions in binary form must reproduce the above copyright
134: notice, this list of conditions and the following disclaimer in the
135: documentation and/or other materials provided with the distribution.
136:
137: 3. The name of the author may not be used to endorse or promote products
138: derived from this software without specific prior written permission.
139:
140: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
141: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
142: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
143: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
144: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
145: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
146: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
147: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
148: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
149: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150: */
|