[Mulgara-svn] r1766 - trunk/src/jar/query/java/org/mulgara/connection

pag at mulgara.org pag at mulgara.org
Tue Aug 11 00:23:58 UTC 2009


Author: pag
Date: 2009-08-10 17:23:57 -0700 (Mon, 10 Aug 2009)
New Revision: 1766

Added:
   trunk/src/jar/query/java/org/mulgara/connection/JenaConnectionImpl.java
Modified:
   trunk/src/jar/query/java/org/mulgara/connection/Connection.java
   trunk/src/jar/query/java/org/mulgara/connection/SessionConnection.java
Log:
Isolated the Jena interfaces into an external object, so that Jena is not needed in the classpath unless explicitly required.

Modified: trunk/src/jar/query/java/org/mulgara/connection/Connection.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/connection/Connection.java	2009-07-10 16:42:21 UTC (rev 1765)
+++ trunk/src/jar/query/java/org/mulgara/connection/Connection.java	2009-08-11 00:23:57 UTC (rev 1766)
@@ -87,7 +87,7 @@
  * @copyright &copy; 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
  * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
  */
-public interface Connection extends JenaConnection {
+public interface Connection {
 
   /**
    * Give login credentials and security domain to the current session.  This should only be needed

Added: trunk/src/jar/query/java/org/mulgara/connection/JenaConnectionImpl.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/connection/JenaConnectionImpl.java	                        (rev 0)
+++ trunk/src/jar/query/java/org/mulgara/connection/JenaConnectionImpl.java	2009-08-11 00:23:57 UTC (rev 1766)
@@ -0,0 +1,165 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.connection;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.mulgara.jena.GraphMulgara;
+import org.mulgara.query.QueryException;
+
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.shared.JenaException;
+
+/**
+ * Implements operations expected by a Jena client.
+ *
+ * @created Aug 11, 2009
+ * @author Paul Gearon
+ * @copyright &copy; 2009 <a href="http://www.duraspace.org/">DuraSpace</a>
+ */
+public class JenaConnectionImpl implements JenaConnection {
+
+  /** The internal connection to do the real work */
+  private final SessionConnection internalConnection;
+
+
+  public JenaConnectionImpl(SessionConnection connection) {
+    internalConnection = connection;
+  }
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Model.  
+   * Does not create the remote model.
+   * @param graphURI The URI,as a string, of the Mulgara model in the server 
+   * @return A Jena Model
+   */
+  public Model connectModel(String graphURI) {
+    return connectModel(graphURI, false);
+  }
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Model,
+   * creating the model if it does not already exist.
+   * @param graphURI The URI,as a string, of the Mulgara model in the server 
+   * @return A Jena Model
+   */
+  public Model createModel(String graphURI) {
+    return connectModel(graphURI, true);
+  }
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Model.
+   * @param graphURI The URI,as a string, of the Mulgara model in the server 
+   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
+   * @return A Jena Model
+   */
+  public Model connectModel(String graphURI, boolean createIfDoesNotExist) {
+    try {
+      return connectModel(new URI(graphURI), createIfDoesNotExist);
+    } catch (URISyntaxException ex) {
+      throw new JenaException("JenaMulgara.createModel", ex);
+    }
+  }
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Model.
+   * @param graphURI The URI of the Mulgara model.
+   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
+   * @return A Jena Model
+   */
+  public Model connectModel(URI graphURI, boolean createIfDoesNotExist) {
+    Graph g = connectGraph(graphURI, createIfDoesNotExist);
+    return ModelFactory.createModelForGraph(g);
+  }
+
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Model. Does not create the remote model.
+   * @param graphURI The URI,as a string, of the Mulgara model in the server 
+   * @return A Jena Model
+   */
+  public Graph connectGraph(String graphURI) {
+    return connectGraph(graphURI, false);
+  }
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Model.  
+   * Creates the remote graph if it does not already exist.
+   * @param graphURI The URI,as a string, of the Mulgara model in the server 
+   * @return A Jena Model
+   */
+  public Graph createGraph(String graphURI) {
+    return connectGraph(graphURI, true);
+  }
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Graph.
+   * @param graphURI The URI,as a string, of the Mulgara model in the server 
+   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
+   * @return A Jena Model
+   */
+  public Graph connectGraph(String graphURI, boolean createIfDoesNotExist) {
+    try {
+      return connectGraph(new URI(graphURI), createIfDoesNotExist);
+    } catch (URISyntaxException ex) {
+      throw new JenaException("JenaMulgara.connectGraph", ex);
+    }
+  }
+
+  /**
+   * Connect to RDF data stored in a Mulgara server as a Jena Graph.
+   * @param graphURI The URI of the Mulgara model.
+   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
+   * @return A Jena Graph
+   */
+  public Graph connectGraph(URI graphURI, boolean createIfDoesNotExist) {
+    if (createIfDoesNotExist) {
+      try {
+        if (!internalConnection.session.modelExists(graphURI)) internalConnection.session.createModel(graphURI, null);
+      } catch (QueryException ex) {
+        throw new JenaException(ex);
+      }
+    }
+    return new GraphMulgara(internalConnection.session, graphURI) ;
+  }
+
+
+  /**
+   * Drop the Mulgara graph/model.
+   * @param graphURI The URI of the graph
+   */
+  public void dropGraph(String graphURI) {
+    try {
+      dropGraph(new URI(graphURI)) ;
+    } catch (URISyntaxException ex) {
+      throw new JenaException("JenaMulgara.dropGraph", ex);
+    }
+  }
+
+
+  /**
+   * Drop the Mulgara graph/model.
+   * @param graphURI The URI of the graph
+   */
+  public void dropGraph(URI graphURI) {
+    try {
+      internalConnection.session.removeModel(graphURI);
+    } catch (Exception ex) {
+      throw new JenaException("JenaMulgara.dropGraph", ex);
+    }
+  }
+
+}

Modified: trunk/src/jar/query/java/org/mulgara/connection/SessionConnection.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/connection/SessionConnection.java	2009-07-10 16:42:21 UTC (rev 1765)
+++ trunk/src/jar/query/java/org/mulgara/connection/SessionConnection.java	2009-08-11 00:23:57 UTC (rev 1766)
@@ -12,10 +12,8 @@
 package org.mulgara.connection;
 
 import java.net.URI;
-import java.net.URISyntaxException;
 
 import org.apache.log4j.Logger;
-import org.mulgara.jena.GraphMulgara;
 import org.mulgara.query.QueryException;
 import org.mulgara.server.NonRemoteSessionException;
 import org.mulgara.server.Session;
@@ -23,11 +21,6 @@
 import org.mulgara.server.driver.SessionFactoryFinder;
 import org.mulgara.server.driver.SessionFactoryFinderException;
 
-import com.hp.hpl.jena.graph.Graph;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.shared.JenaException;
-
 /**
  * A connection for sending commands to a server using a session object.
  *
@@ -48,7 +41,7 @@
   private URI securityDomainUri;
   
   /** The session to use for this connection. */
-  private Session session;
+  Session session;
   
   /** The factory used to create this connection */
   private ConnectionFactory factory = null;
@@ -308,136 +301,13 @@
   }
 
 
-  ///////////////////////////////////////////////////////////////////////
-  // The JenaConnection interface
-  ///////////////////////////////////////////////////////////////////////
-
   /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Model. Does not create the remote model.
-   * @param graphURI The URI,as a string, of the Mulgara model in the server 
-   * @return A Jena Model
+   * Provides access to a JenaConnection. This interface is isolated from this class
+   * to avoid needing Jena on the classpath.
+   * @return A new JenaConnection object which refers back to this object.
    */
-  public Graph connectGraph(String graphURI) {
-    return connectGraph(graphURI, false);
+  public JenaConnection getJenaConnection() {
+    return new JenaConnectionImpl(this);
   }
 
-
-  /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Graph.
-   * @param graphURI The URI,as a string, of the Mulgara model in the server 
-   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
-   * @return A Jena Model
-   */
-  public Graph connectGraph(String graphURI, boolean createIfDoesNotExist) {
-    try {
-      return connectGraph(new URI(graphURI), createIfDoesNotExist);
-    } catch (URISyntaxException ex) {
-      throw new JenaException("JenaMulgara.connectGraph", ex);
-    }
-  }
-
-
-  /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Graph.
-   * @param graphURI The URI of the Mulgara model.
-   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
-   * @return A Jena Graph
-   */
-  public Graph connectGraph(URI graphURI, boolean createIfDoesNotExist) {
-    if (createIfDoesNotExist) {
-      try {
-        if (!session.modelExists(graphURI)) session.createModel(graphURI, null);
-      } catch (QueryException ex) {
-        throw new JenaException(ex);
-      }
-    }
-    return new GraphMulgara(session, graphURI) ;
-  }
-
-
-  /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Model.  
-   * Does not create the remote model.
-   * @param graphURI The URI,as a string, of the Mulgara model in the server 
-   * @return A Jena Model
-   */
-  public Model connectModel(String graphURI) {
-    return connectModel(graphURI, false);
-  }
-
-
-  /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Model.
-   * @param graphURI The URI,as a string, of the Mulgara model in the server 
-   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
-   * @return A Jena Model
-   */
-  public Model connectModel(String graphURI, boolean createIfDoesNotExist) {
-    try {
-      return connectModel(new URI(graphURI), createIfDoesNotExist);
-    } catch (URISyntaxException ex) {
-      throw new JenaException("JenaMulgara.createModel", ex);
-    }
-  }
-
-
-  /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Model.
-   * @param graphURI The URI of the Mulgara model.
-   * @param createIfDoesNotExist Create the Mulgara model if it does not already exist.
-   * @return A Jena Model
-   */
-  public Model connectModel(URI graphURI, boolean createIfDoesNotExist) {
-    Graph g = connectGraph(graphURI, createIfDoesNotExist);
-    return ModelFactory.createModelForGraph(g);
-  }
-
-
-  /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Model.  
-   * Creates the remote graph if it does not already exist.
-   * @param graphURI The URI,as a string, of the Mulgara model in the server 
-   * @return A Jena Model
-   */
-  public Graph createGraph(String graphURI) {
-    return connectGraph(graphURI, true);
-  }
-
-
-  /**
-   * Connect to RDF data stored in a Mulgara server as a Jena Model,
-   * creating the model if it does not already exist.
-   * @param graphURI The URI,as a string, of the Mulgara model in the server 
-   * @return A Jena Model
-   */
-  public Model createModel(String graphURI) {
-    return connectModel(graphURI, true);
-  }
-
-
-  /**
-   * Drop the Mulgara graph/model.
-   * @param graphURI The URI of the graph
-   */
-  public void dropGraph(String graphURI) {
-    try {
-      dropGraph(new URI(graphURI)) ;
-    } catch (URISyntaxException ex) {
-      throw new JenaException("JenaMulgara.dropGraph", ex);
-    }
-  }
-
-
-  /**
-   * Drop the Mulgara graph/model.
-   * @param graphURI The URI of the graph
-   */
-  public void dropGraph(URI graphURI) {
-    try {
-      session.removeModel(graphURI);
-    } catch (Exception ex) {
-      throw new JenaException("JenaMulgara.dropGraph", ex);
-    }
-  }
-
 }




More information about the Mulgara-svn mailing list