KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joseki > server > ModelSet


1 /*
2  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package org.joseki.server;
7
8 import java.util.* ;
9 import org.apache.commons.logging.* ;
10 import java.io.* ;
11
12 import org.joseki.server.source.* ;
13 import com.hp.hpl.jena.rdf.model.* ;
14
15 /**
16  * A ModelSet is a collection of RDF models to be made available, together with the
17  * specific configuration for that set. Models themselves can have specific, custom
18  * functionalty.
19  *
20  * @author Andy Seaborne
21  * @version $Id: ModelSet.java,v 1.10 2004/04/30 14:13:13 andy_seaborne Exp $
22  */

23
24
25 public class ModelSet {
26     private static Log logger = LogFactory.getLog("org.joseki.server.ModelSet");
27     
28     // Current models, indexed by external name
29
HashMap modelMap = new HashMap() ;
30
31     /** Merge a configuration file into a model set.
32      */

33
34     public ModelSet load(String JavaDoc configFile) throws FileNotFoundException, RDFException
35     {
36         Configuration config = new Configuration() ;
37         config.load(this, configFile) ;
38         return this ;
39     }
40
41     /** Create an empty ModelSet */
42     public ModelSet()
43     {
44     }
45     
46     public ModelSource findModel(String JavaDoc sourceURI)
47     {
48         return (ModelSource)modelMap.get(sourceURI) ;
49     }
50     
51     
52     /** Add an ModelSource to the ModelSet.
53      *
54      * @param sourceURI The external URI that the model will appear under
55      * @param aModel The ModelSource.
56      * @see ModelSource
57      */

58     
59     public void addModel(String JavaDoc sourceURI, ModelSource aModel)
60     {
61         modelMap.put(sourceURI, aModel) ;
62     }
63     
64     /** Add a Jena model to the ModelSet.
65      * Preferred mechanism is to added an AttachedModel.
66      *
67      * @param sourceURI The external URI that the model will appear under
68      * @param model The RDF model.
69      * @see ModelSource
70      */

71     
72     public void addModel(String JavaDoc sourceURI, Model model)
73     {
74         // Not preferred
75
modelMap.put(sourceURI, new ModelSourcePermanent(null, model, sourceURI)) ;
76     }
77
78     /** Remove a model from the ModelSet.
79      *
80      * @param sourceURI The external URI that the model currently appreas under.
81      */

82     
83     public void removeModel(String JavaDoc sourceURI)
84     {
85         ModelSource m = findModel(sourceURI) ;
86         if ( m != null )
87         {
88             modelMap.remove(sourceURI) ;
89             m.release() ;
90         }
91     }
92     
93     public int size() { return modelMap.size() ; }
94     public Iterator sourceURIs() { return modelMap.keySet().iterator() ; }
95     
96     final static String JavaDoc serverRootURI = "http://server/" ;
97
98     // Turn a config file URI into an entry for the attached models table.
99
static String JavaDoc resource2serverURI(Resource r)
100     {
101         String JavaDoc serverURI = r.getURI();
102         if ( ! serverURI.startsWith(serverRootURI) )
103             logger.warn("URI '"+serverURI+"' for attached model does not start '"+serverRootURI+"'") ;
104         
105         // Take off the initial serverRootURI declaration
106
// URIs of servlet requests do not have the host name attached.
107
// ie. they are relative URI - relative to the web server.
108
serverURI = "/" + serverURI.substring(serverRootURI.length());
109         return serverURI ;
110     }
111 }
112
113 /*
114  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
115  * All rights reserved.
116  *
117  * Redistribution and use in source and binary forms, with or without
118  * modification, are permitted provided that the following conditions
119  * are met:
120  * 1. Redistributions of source code must retain the above copyright
121  * notice, this list of conditions and the following disclaimer.
122  * 2. Redistributions in binary form must reproduce the above copyright
123  * notice, this list of conditions and the following disclaimer in the
124  * documentation and/or other materials provided with the distribution.
125  * 3. The name of the author may not be used to endorse or promote products
126  * derived from this software without specific prior written permission.
127  *
128  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
129  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
130  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
131  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
132  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
133  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
134  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
135  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
137  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138  */

139
Popular Tags