improvements from the list suggested by Domel and Mo McRoberts <mo.mcroberts@bbc.co.uk> webid
authorHenry Story <henry.story@bblfish.net>
Wed, 23 Nov 2011 15:22:01 +0100
branchwebid
changeset 139 cc0fb90aa327
parent 129 0e0d7212e63c
child 140 9993d3594e1a
improvements from the list suggested by Domel and Mo McRoberts <mo.mcroberts@bbc.co.uk>
src/main/scala/auth/earl.scala
--- a/src/main/scala/auth/earl.scala	Sun Nov 20 01:15:14 2011 +0100
+++ b/src/main/scala/auth/earl.scala	Wed Nov 23 15:22:01 2011 +0100
@@ -27,7 +27,8 @@
 import java.security.cert.X509Certificate
 import java.security.interfaces.RSAPublicKey
 import org.w3.readwriteweb.util.trySome
-import com.hp.hpl.jena.rdf.model.{Property, ModelFactory}
+import java.lang.ref.WeakReference
+import com.hp.hpl.jena.rdf.model.{Model, Property, ModelFactory}
 
 /**
  * Classes for the tests in WebID Authentication.
@@ -48,10 +49,15 @@
   val ns = "http://www.w3.org/2005/Incubator/webid/earl/RelyingParty"
   val skos = "http://www.w3.org/2004/02/skos/core#"
 
+  private var m : WeakReference[Model] = null
+  
   //todo: this model should be a weak pointer
-  val model= ModelFactory.createDefaultModel().read(
-    this.getClass.getResourceAsStream("/ontologies/RelyingParty.n3"),
-    ns,  "TURTLE" )
+   def model= {
+     if (m==null || m.get() == null) m = new WeakReference( ModelFactory.createDefaultModel().read(
+       this.getClass.getResourceAsStream("/ontologies/RelyingParty.n3"),
+       ns,  "TURTLE" ) )
+     m.get;
+   }
 
 
 }