KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > impl > WrappedReasonerFactory


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: WrappedReasonerFactory.java,v 1.6 2005/04/10 12:45:51 chris-dollin Exp $
5 */

6 package com.hp.hpl.jena.reasoner.rulesys.impl;
7
8 import com.hp.hpl.jena.rdf.model.*;
9 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     {
21     protected final ReasonerFactory factory;
22     protected final Resource config;
23     
24     protected final Model schemaUnion = ModelFactory.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          Answer a Reasoner created according to the underlying factory, and then
34          loaded with this Wrapper's rules (if the Reasoner is a RuleReasoner) and
35          bound to this Wrapper's schemas (in an unspecified order).
36      */

37     public Reasoner create( Resource ignored )
38         { Reasoner result = factory.create( config );
39         return schemaUnion.isEmpty() ? result : result.bindSchema( schemaUnion ); }
40     
41     private static Model loadSchemas( Model schema, Resource R )
42         {
43         StmtIterator schemas = R.listProperties( JenaModelSpec.schemaURL );
44         while (schemas.hasNext())
45             {
46             Statement s = schemas.nextStatement();
47             Resource sc = s.getResource();
48             FileManager.get().readModel( schema, sc.getURI() );
49             }
50         return schema;
51         }
52     
53     /**
54          Answer the capabilities of the underlying ReasonerFactory.
55     */

56     public Model getCapabilities()
57         { return factory.getCapabilities(); }
58     
59     /**
60          Answer the URI of the underlying ReasonerFactory.
61     */

62     public String JavaDoc getURI()
63         { return factory.getURI(); }
64     }
65
66 /*
67     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
68     All rights reserved.
69     
70     Redistribution and use in source and binary forms, with or without
71     modification, are permitted provided that the following conditions
72     are met:
73     
74     1. Redistributions of source code must retain the above copyright
75        notice, this list of conditions and the following disclaimer.
76     
77     2. Redistributions in binary form must reproduce the above copyright
78        notice, this list of conditions and the following disclaimer in the
79        documentation and/or other materials provided with the distribution.
80     
81     3. The name of the author may not be used to endorse or promote products
82        derived from this software without specific prior written permission.
83     
84     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
85     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
86     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
87     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
88     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
89     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
90     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
91     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
92     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
93     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
94 */
Popular Tags