01: /*
02: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
03: [See end of file]
04: $Id: WrappedReasonerFactory.java,v 1.9 2008/01/02 12:06:16 andy_seaborne Exp $
05: */
06: package com.hp.hpl.jena.reasoner.rulesys.impl;
07:
08: import com.hp.hpl.jena.rdf.model.*;
09: import com.hp.hpl.jena.reasoner.*;
10: import com.hp.hpl.jena.util.FileManager;
11: import com.hp.hpl.jena.vocabulary.JenaModelSpec;
12:
13: /**
14: WrappedReasonerFactory - a wrapper round ReasonerFactories that
15: accepts a Resource configuring initial rules, schemas, etc.
16:
17: @author kers
18: */
19: public final class WrappedReasonerFactory implements ReasonerFactory {
20: protected final ReasonerFactory factory;
21: protected final Resource config;
22:
23: protected final Model schemaUnion = ModelFactory
24: .createDefaultModel();
25:
26: public WrappedReasonerFactory(ReasonerFactory rrf, Resource config) {
27: super ();
28: this .factory = rrf;
29: this .config = config;
30: loadSchemas(schemaUnion, config);
31: }
32:
33: /**
34: Answer a Reasoner created according to the underlying factory, and then
35: loaded with this Wrapper's rules (if the Reasoner is a RuleReasoner) and
36: bound to this Wrapper's schemas (in an unspecified order).
37: */
38: public Reasoner create(Resource ignored) {
39: Reasoner result = factory.create(config);
40: return schemaUnion.isEmpty() ? result : result
41: .bindSchema(schemaUnion);
42: }
43:
44: private static Model loadSchemas(Model schema, Resource R) {
45: StmtIterator schemas = R
46: .listProperties(JenaModelSpec.schemaURL);
47: while (schemas.hasNext()) {
48: Statement s = schemas.nextStatement();
49: Resource sc = s.getResource();
50: FileManager.get().readModel(schema, sc.getURI());
51: }
52: return schema;
53: }
54:
55: /**
56: Answer the capabilities of the underlying ReasonerFactory.
57: */
58: public Model getCapabilities() {
59: return factory.getCapabilities();
60: }
61:
62: /**
63: Answer the URI of the underlying ReasonerFactory.
64: */
65: public String getURI() {
66: return factory.getURI();
67: }
68: }
69:
70: /*
71: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
72: All rights reserved.
73:
74: Redistribution and use in source and binary forms, with or without
75: modification, are permitted provided that the following conditions
76: are met:
77:
78: 1. Redistributions of source code must retain the above copyright
79: notice, this list of conditions and the following disclaimer.
80:
81: 2. Redistributions in binary form must reproduce the above copyright
82: notice, this list of conditions and the following disclaimer in the
83: documentation and/or other materials provided with the distribution.
84:
85: 3. The name of the author may not be used to endorse or promote products
86: derived from this software without specific prior written permission.
87:
88: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
89: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
90: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
91: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
92: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
93: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
94: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
95: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
96: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
97: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98: */
|