[Mulgara-svn] r245 - branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed
pag at mulgara.org
pag at mulgara.org
Fri Apr 20 15:45:47 UTC 2007
Author: pag
Date: 2007-04-20 10:45:47 -0500 (Fri, 20 Apr 2007)
New Revision: 245
Added:
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/ForeignBlankNode.java
Modified:
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java
branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java
Log:
Adding server info to Answers so blank nodes can be associated with a server
Modified: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java 2007-04-20 15:44:28 UTC (rev 244)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/AnswerResolution.java 2007-04-20 15:45:47 UTC (rev 245)
@@ -14,11 +14,15 @@
import org.apache.log4j.Logger; // Apache Log4J
+import org.jrdf.graph.Node;
import org.mulgara.query.Answer;
import org.mulgara.query.Constraint;
+import org.mulgara.query.TuplesException;
import org.mulgara.query.rdf.URIReferenceImpl;
+import org.mulgara.query.rdf.BlankNodeImpl;
import org.mulgara.resolver.spi.GlobalizeException;
+import org.mulgara.resolver.spi.LocalizeException;
import org.mulgara.resolver.spi.LocalizedTuples;
import org.mulgara.resolver.spi.ResolverSession;
import org.mulgara.resolver.spi.Resolution;
@@ -27,6 +31,8 @@
import org.mulgara.store.tuples.RowComparator;
import org.mulgara.store.tuples.Tuples;
+import java.net.URI;
+
/**
* A {@link Resolution} which extends a LocalizedTuples, which in turn wraps an Answer.
*
@@ -44,6 +50,9 @@
/** The constraint. */
private final Constraint constraint;
+
+ /** The server URI being accessed. */
+ private final URI serverUri;
/**
@@ -53,10 +62,11 @@
* @param constraint the constraint.
* @throws IllegalArgumentException if <var>constraint<var> is <code>null</code>
*/
- AnswerResolution(ResolverSession session, Answer answer, Constraint constraint) {
+ AnswerResolution(URI serverUri, ResolverSession session, Answer answer, Constraint constraint) {
super(session, answer);
if (constraint == null) throw new IllegalArgumentException("Null constraint parameter");
this.constraint = constraint;
+ this.serverUri = serverUri;
}
@@ -76,4 +86,22 @@
return true;
}
+ /**
+ * Get the bound value for the column, converting Blank Nodes to a
+ * remote representation when needed.
+ * @param column The column of the bound value.
+ * @return the Localized long integer for the bound value.
+ * @throws TuplesException Indicates an error getting the value from the string pool.
+ */
+ public long getColumnValue(int column) throws TuplesException {
+ try {
+ Object obj = answer.getObject(column);
+ assert obj instanceof Node;
+
+ Node node = obj instanceof BlankNodeImpl ? new ForeignBlankNode(serverUri, (BlankNodeImpl)obj) : (Node)obj;
+ return session.localize(node);
+ } catch (LocalizeException e) {
+ throw new TuplesException("Couldn't localize column " + column, e);
+ }
+ }
}
Added: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/ForeignBlankNode.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/ForeignBlankNode.java 2007-04-20 15:44:28 UTC (rev 244)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/ForeignBlankNode.java 2007-04-20 15:45:47 UTC (rev 245)
@@ -0,0 +1,74 @@
+/*
+ * 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.resolver.distributed;
+
+import org.mulgara.query.rdf.BlankNodeImpl;
+import java.net.URI;
+
+/**
+ * A BlankNode that represents nodes from a foreign server.
+ *
+ * @created 2007-04-18
+ * @author Paul Gearon
+ * @version $Revision: $
+ * @modified $Date: $ @maintenanceAuthor $Author: $
+ * @copyright © 2007 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+ at SuppressWarnings("serial")
+public class ForeignBlankNode extends BlankNodeImpl {
+
+ /** The URI of the foreign server. */
+ URI serverUri;
+
+ public ForeignBlankNode(URI serverUri, BlankNodeImpl remoteNode) {
+ super(remoteNode.getNodeId());
+ this.serverUri = serverUri;
+ }
+
+
+ /**
+ * Provide a representation that is unique for this node.
+ * @return A string containing all the unique features of the node.
+ */
+ public String toString() {
+ return serverUri.toString() + ":_" + getNodeId();
+ }
+
+
+ /**
+ * Compare node for equality.
+ *
+ * @param obj The object to compare against.
+ * @return True if the object evaluates as an equivalent blank node.
+ */
+ public boolean equals(Object obj) {
+ if (obj == null) return false;
+ if (obj == this) return true;
+ if (obj instanceof ForeignBlankNode) {
+ ForeignBlankNode fbn = (ForeignBlankNode)obj;
+ return (serverUri.equals(fbn.serverUri) && getNodeId() == fbn.getNodeId());
+ }
+ return false;
+ }
+
+
+ /**
+ * Reproducable hashcode for the object.
+ * @return Hashcode of the nodeid.
+ */
+ public int hashCode() {
+ long nodeId = getNodeId();
+ return serverUri.hashCode() ^ (int)(nodeId ^ (nodeId >>>32));
+ }
+
+}
Modified: branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java
===================================================================
--- branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java 2007-04-20 15:44:28 UTC (rev 244)
+++ branches/blank_nodes/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/NetworkDelegator.java 2007-04-20 15:45:47 UTC (rev 245)
@@ -32,7 +32,6 @@
import org.mulgara.server.driver.SessionFactoryFinderException;
import org.mulgara.resolver.spi.GlobalizeException;
import org.mulgara.resolver.spi.Resolution;
-import org.mulgara.resolver.spi.ResolverException;
import org.mulgara.resolver.spi.ResolverSession;
import org.jrdf.graph.Node;
@@ -94,8 +93,9 @@
URI modelUri = model.getURI();
testForLocality(modelUri);
- Answer ans = getModelSession(modelUri).query(globalizedQuery(localConstraint, model));
- return new AnswerResolution(session, ans, localConstraint);
+ URI serverUri = getServerUri(modelUri);
+ Answer ans = getServerSession(serverUri).query(globalizedQuery(localConstraint, model));
+ return new AnswerResolution(serverUri, session, ans, localConstraint);
}
@@ -185,21 +185,19 @@
/**
- * Gets a remote session on a server specified by a given model URI.
- * @param modelUri The URI of the model to get a session for.
- * @return a remote session on the host found in the model.
- * @throws QueryException Thrown when the model is a bad URI, or the session cannot be created.
+ * Gets the URI for a server.
+ * @param modelUri The URI of the model we are getting the server for.
+ * @return A new URI containing just the server information.
*/
- protected Session getModelSession(URI modelUri) throws QueryException {
- try {
+ protected static URI getServerUri(URI modelUri) {
+ try {
// use the URI without the model fragment
- return getServerSession(new URI(modelUri.getScheme(), modelUri.getSchemeSpecificPart(), null));
+ return new URI(modelUri.getScheme(), modelUri.getSchemeSpecificPart(), null);
} catch (URISyntaxException use) {
throw new AssertionError(use);
}
}
-
/**
* Retrieves a session for a given server URI, using a cached value if possible.
* @param serverUri The URI of the server to get a session for.
More information about the Mulgara-svn
mailing list