01: /*
02: (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: All rights reserved - see end of file.
04: $Id: OntModelAssembler.java,v 1.9 2008/01/03 15:19:05 chris-dollin 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.ontology.*;
13: import com.hp.hpl.jena.rdf.model.*;
14:
15: public class OntModelAssembler extends InfModelAssembler implements
16: Assembler {
17: public Model openEmptyModel(Assembler a, Resource root, Mode mode) {
18: checkType(root, JA.OntModel);
19: Model baseModel = getBase(a, root, mode);
20: OntModelSpec oms = getOntModelSpec(a, root);
21: OntModel om = ModelFactory.createOntologyModel(oms, baseModel);
22: addSubModels(a, root, mode, om);
23: return om;
24: }
25:
26: private void addSubModels(Assembler a, Resource root, Mode mode,
27: OntModel om) {
28: List subModels = getSubModels(a, root, mode);
29: for (Iterator it = subModels.iterator(); it.hasNext();)
30: om.addSubModel((Model) it.next());
31: }
32:
33: private List getSubModels(Assembler a, Resource root, Mode mode) {
34: List result = new ArrayList();
35: for (StmtIterator it = root.listProperties(JA.subModel); it
36: .hasNext();)
37: result.add(a.openModel(it.nextStatement().getResource(),
38: mode));
39: return result;
40: }
41:
42: private static final OntModelSpec defaultSpec = OntModelSpec.OWL_MEM_RDFS_INF;
43:
44: protected OntModelSpec getOntModelSpec(Assembler a, Resource root) {
45: Resource r = getUniqueResource(root, JA.ontModelSpec);
46: return r == null ? defaultSpec : (OntModelSpec) a.open(r);
47: }
48: }
49:
50: /*
51: * (c) Copyright 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
52: * All rights reserved.
53: *
54: * Redistribution and use in source and binary forms, with or without
55: * modification, are permitted provided that the following conditions
56: * are met:
57: * 1. Redistributions of source code must retain the above copyright
58: * notice, this list of conditions and the following disclaimer.
59: * 2. Redistributions in binary form must reproduce the above copyright
60: * notice, this list of conditions and the following disclaimer in the
61: * documentation and/or other materials provided with the distribution.
62: * 3. The name of the author may not be used to endorse or promote products
63: * derived from this software without specific prior written permission.
64: *
65: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
66: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
67: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
68: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
69: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
70: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
71: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
72: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
73: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
74: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
75: */
|