jena-spring

Spring integration for Jena
git clone https://code.djc.id.au/git/jena-spring/
commit a9835454b23fed8e1e3e04d1f443f158955a34bb
parent c9b5ecad3a9e5d19cb158365c0bc9bf0ffa081ac
Author: Dan Callaghan <djc@djc.id.au>
Date:   Tue, 22 Jun 2010 19:57:08 +1000

ModelOperations implementation for shared Model instances

Diffstat:
Asrc/main/java/au/id/djc/jena/util/SingleModelOperator.java | 36++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+), 0 deletions(-)
diff --git a/src/main/java/au/id/djc/jena/util/SingleModelOperator.java b/src/main/java/au/id/djc/jena/util/SingleModelOperator.java
@@ -0,0 +1,36 @@
+package au.id.djc.jena.util;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.util.Assert;
+
+/**
+ * {@link ModelOperations} implementation which always operates on a single
+ * shared in-memory {@link Model} instance.
+ */
+public class SingleModelOperator implements ModelOperations, InitializingBean {
+    
+    private Model model;
+    
+    public SingleModelOperator() {
+    }
+    
+    public SingleModelOperator(Model model) {
+        this.model = model;
+    }
+    
+    public void setModel(Model model) {
+        this.model = model;
+    }
+    
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        Assert.notNull(model, "The 'model' property must not be null");
+    }
+    
+    @Override
+    public <T> T withModel(ModelExecutionCallback<T> callback) {
+        return callback.execute(model);
+    }
+
+}