01: /*
02: * LICENSE INFORMATION
03: * Copyright 2005-2007 by FZI (http://www.fzi.de).
04: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
05: * <OWNER> = Max Völkel
06: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
07: * <YEAR> = 2007
08: *
09: * Project information at http://semweb4j.org/rdf2go
10: */
11: package org.ontoware.rdf2go.impl;
12:
13: import java.util.Properties;
14:
15: import org.ontoware.rdf2go.ModelFactory;
16: import org.ontoware.rdf2go.Reasoning;
17: import org.ontoware.rdf2go.exception.ModelRuntimeException;
18: import org.ontoware.rdf2go.exception.ReasoningNotSupportedException;
19: import org.ontoware.rdf2go.model.Model;
20: import org.ontoware.rdf2go.model.ModelSet;
21:
22: /**
23: * Implmentors musts implement Model getModel(Properties p) and ModelSet
24: * getModelSet(Properties p)
25: *
26: * @author voelkel
27: *
28: */
29: public abstract class AbstractModelFactory implements ModelFactory {
30:
31: // ////////////////////////
32: // implement convenience functions by delegating to the worker methods
33:
34: public Model createModel() throws ModelRuntimeException {
35: Properties properties = new Properties();
36: properties.put(ModelFactory.REASONING, Reasoning.none
37: .toString());
38: properties.put(ModelFactory.STORAGE,
39: ModelFactory.STORAGE_VALUE_MEMORY);
40: return createModel(properties);
41: }
42:
43: public Model createModel(Reasoning reasoning)
44: throws ModelRuntimeException,
45: ReasoningNotSupportedException {
46: Properties properties = new Properties();
47: properties.put(ModelFactory.REASONING, reasoning.toString());
48: properties.put(ModelFactory.STORAGE,
49: ModelFactory.STORAGE_VALUE_MEMORY);
50: return createModel(properties);
51: }
52:
53: public ModelSet createModelSet() throws ModelRuntimeException {
54: Properties properties = new Properties();
55: properties.put(ModelFactory.REASONING, Reasoning.none
56: .toString());
57: properties.put(ModelFactory.STORAGE,
58: ModelFactory.STORAGE_VALUE_MEMORY);
59: return createModelSet(properties);
60: }
61:
62: public ModelSet createModelSet(Reasoning reasoning)
63: throws ModelRuntimeException,
64: ReasoningNotSupportedException {
65: Properties properties = new Properties();
66: properties.put(ModelFactory.REASONING, reasoning.toString());
67: properties.put(ModelFactory.STORAGE,
68: ModelFactory.STORAGE_VALUE_MEMORY);
69: return createModelSet(properties);
70: }
71:
72: /**
73: * Utility function to help using the properties
74: */
75: public static Reasoning getReasoning(Properties p)
76: throws ModelRuntimeException {
77:
78: String reasoningString = (String) p.get(ModelFactory.REASONING);
79:
80: if (reasoningString == null)
81: return Reasoning.none;
82:
83: // else
84: Reasoning reasoning = Reasoning.valueOf(reasoningString);
85: if (reasoning == null)
86: throw new IllegalArgumentException(
87: "Illegal inferencing type: " + reasoningString);
88:
89: // else
90: return reasoning;
91: }
92:
93: }
|