1 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 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 serverURI; 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 uri) 41 { 42 this(ctl) ; 43 serverURI = uri; 44 } 45 46 abstract public Model getModel() ; 47 48 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 prefix, String nsURI) 58 { 59 if ( prefixes == null ) 60 prefixes = new HashMap() ; 61 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 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 165 166 | Popular Tags |