KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.* ;
9 import org.apache.commons.logging.* ;
10 import com.hp.hpl.jena.rdf.model.*;
11 import com.hp.hpl.jena.shared.PrefixMapping.IllegalPrefixException ;
12 import org.joseki.server.* ;
13
14 /** Common code wrapper for source Jena models.
15  *
16  * @author Andy Seaborne
17  * @version $Id: ModelSourceCom.java,v 1.5 2004/04/30 14:13:14 andy_seaborne Exp $
18  */

19
20 abstract class ModelSourceCom implements ModelSourceJena
21 {
22     static Log logger = LogFactory.getLog(ModelSourceCom.class.getName()) ;
23     
24     protected SourceController sourceController = null ;
25     protected String JavaDoc serverURI; // How it appears to the server
26
protected boolean isImmutable = false ;
27     protected boolean isActive = false;
28     
29     private boolean inOperation = false ;
30     private boolean isReadLocked = false ;
31     private boolean isWriteLocked = false ;
32     
33     ProcessorRegistry processors = new ProcessorRegistry() ;
34
35     protected ModelSourceCom(SourceController ctl)
36     {
37         sourceController = ctl ;
38     }
39     
40     protected ModelSourceCom(SourceController ctl, String JavaDoc uri)
41     {
42         this(ctl) ;
43         serverURI = uri;
44     }
45
46     abstract public Model getModel() ;
47
48     // The convenience record of prefixes for this model.
49
Map prefixes = null ;
50     public Map getPrefixes()
51     {
52         if ( prefixes == null )
53             prefixes = new HashMap() ;
54         return prefixes ;
55     }
56
57     public void setPrefix(String JavaDoc prefix, String JavaDoc nsURI)
58     {
59         if ( prefixes == null )
60             prefixes = new HashMap() ;
61         // Set both here and in the underlying model.
62
prefixes.put(prefix, nsURI) ;
63         try { getModel().setNsPrefix(prefix, nsURI) ; } catch (IllegalPrefixException e ) {}
64     }
65
66
67     public synchronized void startOperation(boolean readOnly)
68     {
69         
70         activate() ;
71         if ( getModel().supportsTransactions() )
72             getModel().begin() ;
73         else
74             getModel().enterCriticalSection(readOnly) ;
75     }
76
77     public synchronized void endOperation()
78     {
79         if ( getModel().supportsTransactions() )
80             getModel().commit() ;
81         else
82             getModel().leaveCriticalSection() ;
83         deactivate() ;
84     }
85     
86     public synchronized void abortOperation()
87     {
88         if ( getModel().supportsTransactions() )
89             getModel().abort() ;
90         else
91             getModel().leaveCriticalSection() ;
92         deactivate() ;
93     }
94
95     public void flush() { return ; }
96     
97     public void release()
98     {
99         if (!isActive)
100             return;
101         isActive = false;
102     }
103
104     public boolean isImmutable()
105     {
106         return isImmutable;
107     }
108
109     public void setIsImmutable(boolean isFixed)
110     {
111         isImmutable = isFixed ;
112     }
113
114     public String JavaDoc getServerURI()
115     {
116         return serverURI ;
117     }
118     
119     public ProcessorRegistry getProcessorRegistry()
120     {
121         return processors ;
122     }
123     
124     public void activate()
125     {
126         if ( sourceController != null )
127             sourceController.activate() ;
128     }
129     
130     public void deactivate()
131     {
132         if ( sourceController != null )
133             sourceController.deactivate() ;
134     }
135
136 }
137
138
139 /*
140  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
141  * All rights reserved.
142  *
143  * Redistribution and use in source and binary forms, with or without
144  * modification, are permitted provided that the following conditions
145  * are met:
146  * 1. Redistributions of source code must retain the above copyright
147  * notice, this list of conditions and the following disclaimer.
148  * 2. Redistributions in binary form must reproduce the above copyright
149  * notice, this list of conditions and the following disclaimer in the
150  * documentation and/or other materials provided with the distribution.
151  * 3. The name of the author may not be used to endorse or promote products
152  * derived from this software without specific prior written permission.
153  *
154  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
155  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
156  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
157  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
158  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
159  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
160  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
161  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
162  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
163  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
164  */

165  
166
Popular Tags