01: /*
02: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: All rights reserved - see end of file.
04: $Id: RuleSetAssembler.java,v 1.8 2008/01/02 12:09:36 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.assembler.assemblers;
08:
09: import java.util.*;
10:
11: import com.hp.hpl.jena.assembler.*;
12: import com.hp.hpl.jena.rdf.model.*;
13: import com.hp.hpl.jena.reasoner.rulesys.Rule;
14:
15: public class RuleSetAssembler extends AssemblerBase implements
16: Assembler {
17: public Object open(Assembler a, Resource root, Mode irrelevant) {
18: checkType(root, JA.RuleSet);
19: return createRuleSet(a, root);
20: }
21:
22: public static RuleSet createRuleSet(Assembler a, Resource root) {
23: return RuleSet.create(addRules(new ArrayList(), a, root));
24: }
25:
26: public static List addRules(List result, Assembler a, Resource root) {
27: addLiteralRules(root, result);
28: addIndirectRules(a, root, result);
29: addExternalRules(root, result);
30: return result;
31: }
32:
33: static private void addIndirectRules(Assembler a, Resource root,
34: List result) {
35: StmtIterator it = root.listProperties(JA.rules);
36: while (it.hasNext()) {
37: Resource r = getResource(it.nextStatement());
38: result.addAll(((RuleSet) a.open(r)).getRules());
39: }
40: }
41:
42: static private void addExternalRules(Resource root, List result) {
43: StmtIterator it = root.listProperties(JA.rulesFrom);
44: while (it.hasNext()) {
45: Resource s = getResource(it.nextStatement());
46: result.addAll(Rule.rulesFromURL(s.getURI()));
47: }
48: }
49:
50: static private void addLiteralRules(Resource root, List result) {
51: StmtIterator it = root.listProperties(JA.rule);
52: while (it.hasNext()) {
53: String s = getString(it.nextStatement());
54: result.addAll(Rule.parseRules(s));
55: }
56: }
57: }
58:
59: /*
60: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
61: * All rights reserved.
62: *
63: * Redistribution and use in source and binary forms, with or without
64: * modification, are permitted provided that the following conditions
65: * are met:
66: * 1. Redistributions of source code must retain the above copyright
67: * notice, this list of conditions and the following disclaimer.
68: * 2. Redistributions in binary form must reproduce the above copyright
69: * notice, this list of conditions and the following disclaimer in the
70: * documentation and/or other materials provided with the distribution.
71: * 3. The name of the author may not be used to endorse or promote products
72: * derived from this software without specific prior written permission.
73: *
74: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
75: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
77: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
78: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
79: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
80: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
81: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
82: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
83: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84: */
|