001: /*
002: (c) Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
003: [See end of file]
004: $Id: ModelMakerImpl.java,v 1.26 2008/01/28 15:51:46 chris-dollin Exp $
005: */
006:
007: package com.hp.hpl.jena.rdf.model.impl;
008:
009: import com.hp.hpl.jena.graph.*;
010: import com.hp.hpl.jena.rdf.model.*;
011: import com.hp.hpl.jena.util.iterator.*;
012:
013: /**
014: A ModelMakerImpl implements a ModelMaker over a GraphMaker.
015: */
016: public class ModelMakerImpl implements ModelMaker {
017: protected GraphMaker maker;
018: protected Model description;
019:
020: public ModelMakerImpl(GraphMaker maker) {
021: this .maker = maker;
022: }
023:
024: public GraphMaker getGraphMaker() {
025: return maker;
026: }
027:
028: public void close() {
029: maker.close();
030: }
031:
032: public Model openModel() {
033: return new ModelCom(maker.openGraph());
034: }
035:
036: protected Model makeModel(Graph g) {
037: return new ModelCom(g);
038: }
039:
040: public Model openModelIfPresent(String name) {
041: return maker.hasGraph(name) ? openModel(name) : null;
042: }
043:
044: public Model openModel(String name, boolean strict) {
045: return makeModel(maker.openGraph(name, strict));
046: }
047:
048: public Model openModel(String name) {
049: return openModel(name, false);
050: }
051:
052: public Model createModel(String name, boolean strict) {
053: return makeModel(maker.createGraph(name, strict));
054: }
055:
056: public Model createModel(String name) {
057: return createModel(name, false);
058: }
059:
060: public Model createModelOver(String name) {
061: return createModel(name);
062: }
063:
064: public Model createFreshModel() {
065: return makeModel(maker.createGraph());
066: }
067:
068: public Model createDefaultModel() {
069: return makeModel(maker.getGraph());
070: }
071:
072: public Model getDescription() {
073: if (description == null)
074: description = makeModel(maker.getDescription());
075: return description;
076: }
077:
078: public Model getDescription(Resource root) {
079: return makeModel(maker.getDescription(root.asNode()));
080: }
081:
082: public Model addDescription(Model m, Resource self) {
083: return makeModel(maker.addDescription(m.getGraph(), self
084: .asNode()));
085: }
086:
087: public void removeModel(String name) {
088: maker.removeGraph(name);
089: }
090:
091: public boolean hasModel(String name) {
092: return maker.hasGraph(name);
093: }
094:
095: public ExtendedIterator listModels() {
096: return maker.listGraphs();
097: }
098:
099: /**
100: ModelGetter implementation component.
101: */
102: public Model getModel(String URL) {
103: return hasModel(URL) ? openModel(URL) : null;
104: }
105:
106: public Model getModel(String URL, ModelReader loadIfAbsent) {
107: Model already = getModel(URL);
108: return already == null ? loadIfAbsent.readModel(
109: createModel(URL), URL) : already;
110: }
111: }
112:
113: /*
114: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
115: All rights reserved.
116:
117: Redistribution and use in source and binary forms, with or without
118: modification, are permitted provided that the following conditions
119: are met:
120:
121: 1. Redistributions of source code must retain the above copyright
122: notice, this list of conditions and the following disclaimer.
123:
124: 2. Redistributions in binary form must reproduce the above copyright
125: notice, this list of conditions and the following disclaimer in the
126: documentation and/or other materials provided with the distribution.
127:
128: 3. The name of the author may not be used to endorse or promote products
129: derived from this software without specific prior written permission.
130:
131: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
132: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
133: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
134: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
135: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
136: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
137: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
138: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
139: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
140: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
141: */
|