1 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 23 24 25 public class ModelSet { 26 private static Log logger = LogFactory.getLog("org.joseki.server.ModelSet"); 27 28 HashMap modelMap = new HashMap() ; 30 31 33 34 public ModelSet load(String configFile) throws FileNotFoundException, RDFException 35 { 36 Configuration config = new Configuration() ; 37 config.load(this, configFile) ; 38 return this ; 39 } 40 41 42 public ModelSet() 43 { 44 } 45 46 public ModelSource findModel(String sourceURI) 47 { 48 return (ModelSource)modelMap.get(sourceURI) ; 49 } 50 51 52 58 59 public void addModel(String sourceURI, ModelSource aModel) 60 { 61 modelMap.put(sourceURI, aModel) ; 62 } 63 64 71 72 public void addModel(String sourceURI, Model model) 73 { 74 modelMap.put(sourceURI, new ModelSourcePermanent(null, model, sourceURI)) ; 76 } 77 78 82 83 public void removeModel(String 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 serverRootURI = "http://server/" ; 97 98 static String resource2serverURI(Resource r) 100 { 101 String serverURI = r.getURI(); 102 if ( ! serverURI.startsWith(serverRootURI) ) 103 logger.warn("URI '"+serverURI+"' for attached model does not start '"+serverRootURI+"'") ; 104 105 serverURI = "/" + serverURI.substring(serverRootURI.length()); 109 return serverURI ; 110 } 111 } 112 113 139 | Popular Tags |