You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/11/01 19:47:41 UTC
svn commit: r1196198 -
/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/IRIResolver.java
Author: andy
Date: Tue Nov 1 18:47:41 2011
New Revision: 1196198
URL: http://svn.apache.org/viewvc?rev=1196198&view=rev
Log:
Add locsk on global operations.
Modified:
incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/IRIResolver.java
Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/IRIResolver.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/IRIResolver.java?rev=1196198&r1=1196197&r2=1196198&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/IRIResolver.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/system/IRIResolver.java Tue Nov 1 18:47:41 2011
@@ -100,14 +100,14 @@ public abstract class IRIResolver
// return globalResolver.resolveToString(str) ;
// }
-
+
/**
* The current working directory, as a string.
*/
static private String globalBase = IRILib.filenameToIRI("./") ; // FileUtils.toURL(".").replace("/./", "/") ;
-
+ static private Object globalResolverLock = new Object() ;
private static IRIResolver globalResolver ;
- public static IRIResolver get() { return globalResolver ; }
+ //public static IRIResolver get() { return globalResolver ; }
/**
* The current global resolver based on the working directory
@@ -132,14 +132,18 @@ public abstract class IRIResolver
* @param filename
* @return String The filename as an absolute URL
*/
- static public String resolveFileURL(String filename) throws IRIException {
- IRI r = globalResolver.resolve(filename);
- if (!r.getScheme().equalsIgnoreCase("file"))
+ static public String resolveFileURL(String filename) throws IRIException
+ {
+ synchronized(globalResolverLock)
{
- // Pragmatic hack that copes with "c:"
- return resolveFileURL("./" + filename);
+ IRI r = globalResolver.resolve(filename);
+ if (!r.getScheme().equalsIgnoreCase("file"))
+ {
+ // Pragmatic hack that copes with "c:"
+ return resolveFileURL("./" + filename);
+ }
+ return r.toString();
}
- return r.toString();
}
/**
@@ -153,8 +157,8 @@ public abstract class IRIResolver
* @throws RiotException
* If result would not be legal, absolute IRI
*/
- static public IRI resolve(String relStr, String baseStr)
- throws RiotException {
+ static public IRI resolve(String relStr, String baseStr) throws RiotException
+ {
return exceptions(resolveIRI(relStr, baseStr)) ;
}
@@ -169,26 +173,38 @@ public abstract class IRIResolver
* @throws RiotException
* If result would not be legal, absolute IRI
*/
- static public String resolveString(String relStr, String baseStr)
- throws RiotException {
+ static public String resolveString(String relStr, String baseStr) throws RiotException
+ {
return exceptions(resolveIRI(relStr, baseStr)).toString() ;
}
-
-
+
+ /** Resolve an IRI against whatever is the base for this process
+ * (likely to be based on the current working directory of this process
+ * at the time of initialization of this class).
+ */
+ public static IRI resolveIRI(String uriStr)
+ {
+ return exceptions(globalResolver.resolve(uriStr)) ;
+ }
+
/*
* No exception thrown by this method.
*/
- static private IRI resolveIRI(String relStr, String baseStr) {
- IRI i = iriFactory.create(relStr);
- if (i.isAbsolute())
- // removes excess . segments
- return globalResolver.getBaseIRI().create(i);
-
- IRI base = iriFactory.create(baseStr);
-
- if ("file".equalsIgnoreCase(base.getScheme()))
- return globalResolver.getBaseIRI().create(i);
- return base.create(i);
+ static private IRI resolveIRI(String relStr, String baseStr)
+ {
+ synchronized(globalResolverLock)
+ {
+ IRI i = iriFactory.create(relStr);
+ if (i.isAbsolute())
+ // removes excess . segments
+ return globalResolver.getBaseIRI().create(i);
+
+ IRI base = iriFactory.create(baseStr);
+
+ if ("file".equalsIgnoreCase(base.getScheme()))
+ return globalResolver.getBaseIRI().create(i);
+ return base.create(i);
+ }
}
public static IRIResolver create() { return new IRIResolverNormal() ; }
@@ -212,24 +228,30 @@ public abstract class IRIResolver
* @return String Absolute URI
*/
- static public IRI chooseBaseURI() {
- return globalResolver.getBaseIRI() ;
+ static public IRI chooseBaseURI() {
+ synchronized(globalResolverLock)
+ {
+ return globalResolver.getBaseIRI() ;
+ }
}
/**
* Choose a baseURI based on a suggestion
* @return IRI (if relative, relative to current working directory).
*/
- @Deprecated
- static public IRI chooseBaseURI(String baseURI) {
- if (baseURI == null)
- return chooseBaseURI() ;
- baseURI = "file:.";
- if ( baseURI.startsWith("file:") )
- return globalResolver.resolveSilent(IRILib.filenameToIRI(baseURI)) ;
- else
- return get().resolveSilent(baseURI);
- }
+ @Deprecated
+ static public IRI chooseBaseURI(String baseURI)
+ {
+ synchronized (globalResolver)
+ {
+ if (baseURI == null) return chooseBaseURI() ;
+ baseURI = "file:." ;
+ if (baseURI.startsWith("file:"))
+ return globalResolver.resolveSilent(IRILib.filenameToIRI(baseURI)) ;
+ else
+ return globalResolver.resolveSilent(baseURI) ;
+ }
+ }
public String getBaseIRIasString()
{