KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joseki > server > source > SourceControllerFile


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

5
6 package org.joseki.server.source;
7
8 import org.joseki.vocabulary.JosekiVocab ;
9
10 import com.hp.hpl.jena.rdf.model.* ;
11
12 import org.joseki.server.*;
13 import org.joseki.server.module.Loadable;
14 import org.apache.commons.logging.* ;
15
16 /** SourceController for RDF models held in files.
17  * Does not cause updates to the model to be propagated back to the disk file.
18  *
19  * @author Andy Seaborne
20  * @version $Id: SourceControllerFile.java,v 1.10 2004/04/30 14:13:14 andy_seaborne Exp $
21  */

22
23 public class SourceControllerFile implements SourceController, Loadable
24 {
25     static Log logger = LogFactory.getLog(SourceControllerFile.class.getName()) ;
26     
27     String JavaDoc serverURI ;
28     String JavaDoc filename ;
29     FileManager fileManager ;
30     
31     // ----------------------------------------------------------
32
// -- Loadable interface
33

34     public String JavaDoc getInterfaceURI() { return JosekiVocab.SourceController.getURI() ; }
35     public void init(Resource binding, Resource implementation)
36     {
37         fileManager = FileManager.getInstance() ;
38     }
39     
40     // ----------------------------------------------------------
41
// -- SourceController interface
42

43     // Called once, during configuration
44
public ModelSource createSourceModel(Resource description, String JavaDoc _serverURI)
45     {
46         serverURI = _serverURI ;
47         Statement aModelStmt = description.getProperty(JosekiVocab.attachedModel) ;
48
49         if ( aModelStmt == null )
50         {
51             logger.warn("Model: "+serverURI + " : No internal Jena model specified") ;
52             return null ;
53         }
54         
55         filename = null ;
56         try {
57             filename = aModelStmt.getResource().getURI() ;
58             logger.debug("File source controller: "+serverURI + " ==> " + filename) ;
59         } catch (RDFException ex)
60         {
61             logger.warn("No internal resource URI for "+serverURI) ;
62             return null ;
63         }
64         
65         return new ModelSourceFile(this, serverURI) ;
66     }
67     
68     public String JavaDoc getServerURI() { return serverURI ; }
69     
70     // Called when used.
71
public void activate() { logger.trace("activate: "+filename) ; return ; }
72     
73     // Called when not in use any more.
74
public void deactivate() { logger.trace("deactivate: "+filename) ; return ; }
75
76     // Called each time a source needs to be built.
77
public Model buildSource()
78     {
79         logger.debug("buildSource: "+serverURI+ " ("+filename+")") ;
80         try {
81             return fileManager.loadModel(filename) ;
82         } catch (RDFException rdfEx)
83         {
84             if ( rdfEx.getCause() != null )
85                 logger.warn(filename+": "+rdfEx.getCause()) ;
86             else
87                 logger.warn(filename+": "+rdfEx) ;
88             throw rdfEx ;
89         }
90     }
91     
92     // Called when released (if releasable)
93
public void releaseSource()
94     {
95         logger.debug("releaseSource: "+serverURI+ " ("+filename+")") ;
96     }
97 }
98
99 /*
100  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
101  * All rights reserved.
102  *
103  * Redistribution and use in source and binary forms, with or without
104  * modification, are permitted provided that the following conditions
105  * are met:
106  * 1. Redistributions of source code must retain the above copyright
107  * notice, this list of conditions and the following disclaimer.
108  * 2. Redistributions in binary form must reproduce the above copyright
109  * notice, this list of conditions and the following disclaimer in the
110  * documentation and/or other materials provided with the distribution.
111  * 3. The name of the author may not be used to endorse or promote products
112  * derived from this software without specific prior written permission.
113  *
114  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
115  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
116  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
117  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
118  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
119  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
120  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
121  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
122  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
123  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
124  */

125
Popular Tags