jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1518201 - in /jena/trunk/jena-core/src: main/java/com/hp/hpl/jena/ontology/OntDocumentManager.java main/java/com/hp/hpl/jena/util/FileManager.java test/java/com/hp/hpl/jena/util/TestFileManager.java
Date Wed, 28 Aug 2013 13:35:44 GMT
Author: andy
Date: Wed Aug 28 13:35:44 2013
New Revision: 1518201

URL: http://svn.apache.org/r1518201
Log:
Add and use FileManager.clone()

Modified:
    jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/ontology/OntDocumentManager.java
    jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/util/FileManager.java
    jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/util/TestFileManager.java

Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/ontology/OntDocumentManager.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/ontology/OntDocumentManager.java?rev=1518201&r1=1518200&r2=1518201&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/ontology/OntDocumentManager.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/ontology/OntDocumentManager.java Wed
Aug 28 13:35:44 2013
@@ -23,18 +23,20 @@ package com.hp.hpl.jena.ontology;
 
 // Imports
 ///////////////
-import java.io.*;
-import java.util.*;
+import java.io.InputStream ;
+import java.util.* ;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
 
-import com.hp.hpl.jena.rdf.model.*;
-import com.hp.hpl.jena.util.*;
-import com.hp.hpl.jena.vocabulary.OntDocManagerVocab;
-import com.hp.hpl.jena.vocabulary.RDF;
-import com.hp.hpl.jena.shared.*;
-import com.hp.hpl.jena.shared.impl.PrefixMappingImpl;
+import com.hp.hpl.jena.rdf.model.* ;
+import com.hp.hpl.jena.shared.JenaException ;
+import com.hp.hpl.jena.shared.PrefixMapping ;
+import com.hp.hpl.jena.shared.impl.PrefixMappingImpl ;
+import com.hp.hpl.jena.util.FileManager ;
+import com.hp.hpl.jena.util.FileUtils ;
+import com.hp.hpl.jena.vocabulary.OntDocManagerVocab ;
+import com.hp.hpl.jena.vocabulary.RDF ;
 
 
 /**
@@ -283,7 +285,7 @@ public class OntDocumentManager
      * global location mapper).</p>
      */
     public void setFileManager() {
-        setFileManager( new FileManager( FileManager.get() ) );
+        setFileManager( FileManager.get().clone() ) ;
         m_usingGlobalFileMgr = true;
     }
 

Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/util/FileManager.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/util/FileManager.java?rev=1518201&r1=1518200&r2=1518201&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/util/FileManager.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/util/FileManager.java Wed Aug 28 13:35:44
2013
@@ -72,11 +72,11 @@ public class FileManager
     public static final String filePathSeparator = java.io.File.separator ;
     private static Logger log = LoggerFactory.getLogger(FileManager.class) ;
 
-    static FileManager instance = null ;
+    static FileManager fmInstance = null ;
 
     static boolean logAllLookups = true ; 
-    List<Locator> handlers = new ArrayList<Locator>() ;
-    LocationMapper mapper = null ;
+    protected List<Locator> fmHandlers = new ArrayList<Locator>() ;
+    protected LocationMapper fmMapper = null ;
     
     /** Get the global file manager.
      * @return the global file manager
@@ -84,9 +84,9 @@ public class FileManager
     public static FileManager get()
     {
         // Singleton pattern adopted in case we later have several file managers.
-        if ( instance == null )
-            instance = makeGlobal() ;
-        return instance ;
+        if ( fmInstance == null )
+            fmInstance = makeGlobal() ;
+        return fmInstance ;
     }
     
     /** Set the global file manager (as returned by get())
@@ -95,7 +95,7 @@ public class FileManager
      */
     public static void setGlobalFileManager(FileManager globalFileManager)
     {
-        instance = globalFileManager ;
+        fmInstance = globalFileManager ;
     }
     
     /** Create an uninitialized FileManager */
@@ -105,16 +105,33 @@ public class FileManager
      *  Location mapper and locators chain are copied (the locators are not cloned).
      *  The model cache is not copied and is initially set to not cache.
      * @param filemanager
+     * @deprecated Call filemanager.clone() to get a duplicate FileManager. 
      */
+    @Deprecated
     public FileManager(FileManager filemanager)
     {
-        handlers.addAll(filemanager.handlers) ;
-        mapper = null ;
+        fmHandlers.addAll(filemanager.fmHandlers) ;
+        fmMapper = null ;
         if ( filemanager.getLocationMapper() != null )
-            mapper = new LocationMapper(filemanager.getLocationMapper()) ;
+            fmMapper = new LocationMapper(filemanager.getLocationMapper()) ;
         cacheModelLoads = false ;
         modelCache = null ;
     }
+    
+    @Override
+    public FileManager clone() { return clone(this) ; } 
+ 
+    // Isolate to help avoid copy errors.
+    private static FileManager clone(FileManager filemanager) {
+        FileManager newFm = new FileManager() ;
+        newFm.fmHandlers.addAll(filemanager.fmHandlers) ;
+        newFm.fmMapper = null ;
+        if ( filemanager.getLocationMapper() != null )
+            newFm.fmMapper = new LocationMapper(filemanager.getLocationMapper()) ;
+        newFm.cacheModelLoads = false ;
+        newFm.modelCache = null ;
+        return newFm ;
+    }
 
     /** Create a "standard" FileManager. */
     public static FileManager makeGlobal()
@@ -127,33 +144,33 @@ public class FileManager
     /** Force a file handler to have the default configuration. */
     public static void setStdLocators(FileManager fMgr)
     {
-        fMgr.handlers.clear() ;
+        fMgr.fmHandlers.clear() ;
         fMgr.addLocatorFile() ;
         fMgr.addLocatorURL() ;
         fMgr.addLocatorClassLoader(fMgr.getClass().getClassLoader()) ;
     }
     /** Create with the given location mapper */
     public FileManager(LocationMapper _mapper)    { setLocationMapper(_mapper) ; }
-
+    
     /** @deprecated Use setLocationMapper */
     @Deprecated
     public void setMapper(LocationMapper _mapper) { setLocationMapper(_mapper) ; }
     
     
     /** Set the location mapping */
-    public void setLocationMapper(LocationMapper _mapper) { mapper = _mapper ; }
+    public void setLocationMapper(LocationMapper _mapper) { fmMapper = _mapper ; }
     
     /** Get the location mapping */
-    public LocationMapper getLocationMapper() { return mapper ; }
+    public LocationMapper getLocationMapper() { return fmMapper ; }
     
     /** Return an iterator over all the handlers */
-    public Iterator<Locator> locators() { return handlers.listIterator() ; }
+    public Iterator<Locator> locators() { return fmHandlers.listIterator() ; }
 
     /** Add a locator to the end of the locators list */ 
     public void addLocator(Locator loc)
     {
         log.debug("Add location: "+loc.getName()) ;
-        handlers.add(loc) ; }
+        fmHandlers.add(loc) ; }
 
     /** Add a file locator */ 
     public void addLocatorFile() { addLocatorFile(null) ; } 
@@ -188,7 +205,7 @@ public class FileManager
 
     
     /** Remove a locator */ 
-    public void remove(Locator loc) { handlers.remove(loc) ; }
+    public void remove(Locator loc) { fmHandlers.remove(loc) ; }
 
     // -------- Cache operations
     boolean cacheModelLoads = false ;
@@ -219,27 +236,27 @@ public class FileManager
     /** Read out of the cache - return null if not in the cache */ 
     public Model getFromCache(String filenameOrURI)
     { 
-        if ( ! getCachingModels() )
+        if ( ! isCachingModels() )
             return null; 
         return modelCache.get(filenameOrURI) ;
     }
     
     public boolean hasCachedModel(String filenameOrURI)
     { 
-        if ( ! getCachingModels() )
+        if ( ! isCachingModels() )
             return false ; 
         return modelCache.containsKey(filenameOrURI) ;
     }
     
     public void addCacheModel(String uri, Model m)
     { 
-        if ( getCachingModels() )
+        if ( isCachingModels() )
             modelCache.put(uri, m) ;
     }
 
     public void removeCacheModel(String uri)
     { 
-        if ( getCachingModels() )
+        if ( isCachingModels() )
             modelCache.remove(uri) ;
     }
 
@@ -465,10 +482,10 @@ public class FileManager
     /** Apply the mapping of a filename or URI */
     public String mapURI(String filenameOrURI)
     {
-        if ( mapper == null )
+        if ( fmMapper == null )
             return filenameOrURI ; 
             
-        String uri = mapper.altMapping(filenameOrURI, null) ;
+        String uri = fmMapper.altMapping(filenameOrURI, null) ;
 
         if ( uri == null )
         {
@@ -534,7 +551,7 @@ public class FileManager
     
     public TypedStream openNoMapOrNull(String filenameOrURI)
     {
-        for (Locator loc : handlers)
+        for (Locator loc : fmHandlers)
         {
             TypedStream in = loc.open(filenameOrURI) ;
             if ( in != null )

Modified: jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/util/TestFileManager.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/util/TestFileManager.java?rev=1518201&r1=1518200&r2=1518201&view=diff
==============================================================================
--- jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/util/TestFileManager.java (original)
+++ jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/util/TestFileManager.java Wed Aug 28
13:35:44 2013
@@ -131,7 +131,7 @@ public class TestFileManager extends Tes
     public void testFileManagerClone()
     {
         FileManager fileManager1 = new FileManager() ;
-        FileManager fileManager2 = new FileManager(fileManager1) ;
+        FileManager fileManager2 = fileManager1.clone() ;
         
         // Should not affect fileManager2
         fileManager1.addLocatorFile() ;
@@ -148,7 +148,6 @@ public class TestFileManager extends Tes
         } catch (NotFoundException ex) {}
     }
     
-    
     public void testLocationMappingURLtoFileOpen()
     {
         LocationMapper locMap = new LocationMapper(TestLocationMapper.mapping) ;



Mime
View raw message