[Mulgara-svn] r1546 - trunk/src/jar/resolver-url/java/org/mulgara/resolver/url

pag at mulgara.org pag at mulgara.org
Wed Feb 25 18:51:05 UTC 2009


Author: pag
Date: 2009-02-25 10:51:04 -0800 (Wed, 25 Feb 2009)
New Revision: 1546

Modified:
   trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolver.java
   trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolverFactory.java
   trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLStatements.java
Log:
Reformatting and removing warnings

Modified: trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolver.java
===================================================================
--- trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolver.java	2009-02-25 04:52:21 UTC (rev 1545)
+++ trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolver.java	2009-02-25 18:51:04 UTC (rev 1546)
@@ -79,14 +79,12 @@
    */
   private final ResolverSession resolverSession;
 
-  private final Resolver systemResolver;
-
   /**
    * Map from the {@link URIReference} of each document ever parsed by this
    * resolver to a {@link Map} from {@link ARP}'s {@link String}-valued blank
    * node IDs to {@link BlankNode} instances.
    */
-  private final Map documentMap = new HashMap();
+  private final Map<URIReference,Map<String,BlankNode>> documentMap = new HashMap<URIReference,Map<String,BlankNode>>();
 
   //
   // Constructors
@@ -110,7 +108,6 @@
 
     // Initialize fields
     this.resolverSession = resolverSession;
-    this.systemResolver = systemResolver;
   }
 
   //
@@ -126,11 +123,8 @@
    * @param modelTypeURI  {@inheritDoc}.  This field is ignored, because URL models
    *   are external.
    */
-  public void createModel(long model,
-      URI modelTypeURI) throws ResolverException {
-    if (logger.isDebugEnabled()) {
-      logger.debug("Create URL model " + model);
-    }
+  public void createModel(long model, URI modelTypeURI) throws ResolverException {
+    if (logger.isDebugEnabled()) logger.debug("Create URL model " + model);
 
     // Globalize the model
     URIReference modelURIReference;
@@ -141,8 +135,7 @@
             "Graph parameter " + globalModel + " isn't a URI reference");
       }
       modelURIReference = (URIReference) globalModel;
-    }
-    catch (GlobalizeException e) {
+    } catch (GlobalizeException e) {
       throw new ResolverException("Couldn't globalize model", e);
     }
     assert modelURIReference != null;
@@ -165,8 +158,7 @@
 
         // Open a stream out to the file
         outputStream = new FileOutputStream(new File(url.getPath()));
-      }
-      else {
+      } else {
         // Otherwise, we trust that the Java environment has an appropriate URL
         // protocol handler, and hope furthermore that it supports output
         outputStream = url.openConnection().getOutputStream();
@@ -179,12 +171,10 @@
             new PrintWriter(new OutputStreamWriter(outputStream));
         writer.println("This should be the content of " + modelURIReference);
         writer.flush();
-      }
-      finally {
+      } finally {
         outputStream.close();
       }
-    }
-    catch (IOException e) {
+    } catch (IOException e) {
       throw new ResolverException("Can't create RDF document from " + model, e);
     }
   }
@@ -193,19 +183,14 @@
    * @return a {@link DummyXAResource} with a 10 second transaction timeout
    */
   public XAResource getXAResource() {
-    return new DummyXAResource(
-        10 // seconds before transaction timeout
-        );
+    return new DummyXAResource(10); // seconds before transaction timeout
   }
 
   /**
    * Insert or delete RDF statements in a model at a URL.
    */
-  public void modifyModel(long model, Statements statements,
-      boolean occurs) throws ResolverException {
-    if (logger.isDebugEnabled()) {
-      logger.debug("Modify URL model " + model);
-    }
+  public void modifyModel(long model, Statements statements, boolean occurs) throws ResolverException {
+    if (logger.isDebugEnabled()) logger.debug("Modify URL model " + model);
     throw new ResolverException("Modification of URLs not implemented");
     /*
          logger.error("Choosing an arbitrary scratch model node");
@@ -231,9 +216,7 @@
    * Remove the cached model containing the contents of a URL.
    */
   public void removeModel(long model) throws ResolverException {
-    if (logger.isDebugEnabled()) {
-      logger.debug("Remove URL model " + model);
-    }
+    if (logger.isDebugEnabled())  logger.debug("Remove URL model " + model);
 
     // Globalize the model
     URIReference modelURIReference;
@@ -244,8 +227,7 @@
             "Graph parameter " + globalModel + " isn't a URI reference");
       }
       modelURIReference = (URIReference) globalModel;
-    }
-    catch (GlobalizeException e) {
+    } catch (GlobalizeException e) {
       throw new ResolverException("Couldn't globalize model", e);
     }
     assert modelURIReference != null;
@@ -267,18 +249,15 @@
         if (!(new File(url.getPath()).delete())) {
           logger.warn("Tried to delete nonexistent " + url + " -- ignoring");
         }
-      }
-      else {
+      } else {
         // This is a URL protocol for which we have no specific code
         throw new ResolverException(
             "Can't remove " + url + ": " + url.getProtocol() +
             " protocol not supported");
       }
+    } catch (IOException e) {
+      throw new ResolverException("Can't remove RDF document from " + modelURIReference, e);
     }
-    catch (IOException e) {
-      throw new ResolverException(
-          "Can't remove RDF document from " + modelURIReference, e);
-    }
   }
 
   /**
@@ -287,32 +266,26 @@
    * Resolution is by filtration of a URL stream, and thus very slow.
    */
   public Resolution resolve(Constraint constraint) throws QueryException {
-    if (logger.isDebugEnabled()) {
-      logger.debug("Resolve " + constraint);
-    }
+    if (logger.isDebugEnabled()) logger.debug("Resolve " + constraint);
 
     // Validate parameters
     if (constraint == null) {
       throw new IllegalArgumentException("constraint null");
-    }
-    else if (!(constraint.getModel() instanceof LocalNode)) {
+    } else if (!(constraint.getModel() instanceof LocalNode)) {
       throw new QueryException("Constraint model can't be variable");
     }
 
     // Convert the constraint's model to a URI reference
     URIReference modelURIReference;
     try {
-      Node node = resolverSession.globalize(((LocalNode) constraint.getElement(
-          3)).getValue());
+      Node node = resolverSession.globalize(((LocalNode) constraint.getElement(3)).getValue());
 
       if (!(node instanceof URIReference)) {
-        throw new QueryException("Constraint model " + node +
-            " isn't a URI reference");
+        throw new QueryException("Constraint model " + node + " isn't a URI reference");
       }
 
       modelURIReference = (URIReference) node;
-    }
-    catch (GlobalizeException e) {
+    } catch (GlobalizeException e) {
       throw new QueryException("Couldn't globalize model for " + constraint, e);
     }
     assert modelURIReference != null;
@@ -320,9 +293,9 @@
     // Return the statements in the document at the model URL
     try {
       // Find or create the blank node map for this document
-      Map blankNodeMap = (Map) documentMap.get(modelURIReference);
+      Map<String,BlankNode> blankNodeMap = documentMap.get(modelURIReference);
       if (blankNodeMap == null) {
-        blankNodeMap = new HashMap();
+        blankNodeMap = new HashMap<String,BlankNode>();
         documentMap.put(modelURIReference, blankNodeMap);
       }
       assert blankNodeMap != null;
@@ -331,13 +304,10 @@
       // Generate the resolution
       return new StatementsWrapperResolution(
           constraint,
-          new URLStatements(modelURIReference.getURI().toURL(),
-          resolverSession,
-          blankNodeMap),
+          new URLStatements(modelURIReference.getURI().toURL(), resolverSession, blankNodeMap),
           true // a definitive and complete resolution
           );
-    }
-    catch (MalformedURLException e) {
+    } catch (MalformedURLException e) {
       // This isn't really a document, so return no statements
       Variable[] variables = new Variable[] {new Variable("subject"),
           new Variable("predicate"),
@@ -355,13 +325,9 @@
       catch (TuplesException e2) {
         throw new QueryException("Couldn't generate empty resolution", e2);
       }
-    }
-    catch (IOException e) {
+    } catch (TuplesException e) {
       throw new QueryException("Couldn't read URL " + modelURIReference, e);
     }
-    catch (TuplesException e) {
-      throw new QueryException("Couldn't read URL " + modelURIReference, e);
-    }
   }
 
   public void abort() {}

Modified: trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolverFactory.java
===================================================================
--- trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolverFactory.java	2009-02-25 04:52:21 UTC (rev 1545)
+++ trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLResolverFactory.java	2009-02-25 18:51:04 UTC (rev 1546)
@@ -45,13 +45,12 @@
  *      Software Pty Ltd</a>
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class URLResolverFactory implements ResolverFactory
-{
+public class URLResolverFactory implements ResolverFactory {
   /**
    * Logger.
    */
-  private static Logger logger =
-    Logger.getLogger(URLResolverFactory.class.getName());
+  @SuppressWarnings("unused")
+  private static Logger logger = Logger.getLogger(URLResolverFactory.class.getName());
 
   //
   // Constructors

Modified: trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLStatements.java
===================================================================
--- trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLStatements.java	2009-02-25 04:52:21 UTC (rev 1545)
+++ trunk/src/jar/resolver-url/java/org/mulgara/resolver/url/URLStatements.java	2009-02-25 18:51:04 UTC (rev 1546)
@@ -34,7 +34,6 @@
 import java.net.URL;
 import java.util.*;
 import java.util.zip.GZIPInputStream;
-import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import org.xml.sax.*;
 
@@ -43,14 +42,11 @@
 import com.hp.hpl.jena.rdf.arp.ALiteral;
 import com.hp.hpl.jena.rdf.arp.AResource;
 import com.hp.hpl.jena.rdf.arp.StatementHandler;
-import com.hp.hpl.jena.rdf.arp.StatementHandler;
 import org.apache.log4j.Logger;      // Apache Log4J
 import org.jrdf.graph.*;             // JRDF
 
 // Locally written packages
-import org.mulgara.query.Constraint;
 import org.mulgara.query.Cursor;
-import org.mulgara.query.QueryException;
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
 import org.mulgara.query.rdf.*;
@@ -58,7 +54,6 @@
 import org.mulgara.resolver.spi.ResolverSession;
 import org.mulgara.resolver.spi.Statements;
 import org.mulgara.resolver.spi.StatementsWrapperResolution;
-import org.mulgara.store.StoreException;
 import org.mulgara.store.tuples.AbstractTuples;
 import org.mulgara.store.tuples.Tuples;
 
@@ -82,15 +77,15 @@
   /**
    * Logger.
    */
-  private static final Logger logger =
-    Logger.getLogger(URLStatements.class.getName());
+  @SuppressWarnings("unused")
+  private static final Logger logger = Logger.getLogger(URLStatements.class.getName());
 
   /**
    * The session used to globalize the RDF nodes from the stream.
    */
   private ResolverSession resolverSession;
 
-  private Map blankNodeMap;
+  private Map<String,BlankNode> blankNodeMap;
 
   /**
    * The current row.
@@ -127,23 +122,15 @@
    * @throws TuplesException if the <var>inputStream</var> can't be parsed as
    *   RDF/XML
    */
-  URLStatements(URL url, ResolverSession resolverSession, Map blankNodeMap)
-    throws TuplesException
-  {
+  URLStatements(URL url, ResolverSession resolverSession, Map<String,BlankNode> blankNodeMap) throws TuplesException {
     // Validate "url" parameter
-    if (url == null) {
-      throw new IllegalArgumentException( "Null \"url\" parameter");
-    }
+    if (url == null) throw new IllegalArgumentException( "Null \"url\" parameter");
 
     // Validate "resolverSession" parameter
-    if (resolverSession == null) {
-      throw new IllegalArgumentException("Null \"resolverSession\" parameter");
-    }
+    if (resolverSession == null) throw new IllegalArgumentException("Null \"resolverSession\" parameter");
 
     // Validate "blankNodeMap" parameter
-    if (blankNodeMap == null) {
-      throw new IllegalArgumentException("Null \"blankNodeMap\" parameter");
-    }
+    if (blankNodeMap == null) throw new IllegalArgumentException("Null \"blankNodeMap\" parameter");
 
     // Initialize fields
     this.url             = url;
@@ -224,8 +211,7 @@
   /**
    * The cursor position isn't cloned by this method.
    */
-  public Object clone()
-  {
+  public Object clone() {
     URLStatements cloned = (URLStatements) super.clone();
 
     // Copy immutable fields by reference
@@ -278,13 +264,11 @@
     }
   }
 
-  public List getOperands()
-  {
-    return Collections.EMPTY_LIST;
+  public List<Tuples> getOperands() {
+    return Collections.emptyList();
   }
 
-  public int getRowCardinality() throws TuplesException
-  {
+  public int getRowCardinality() throws TuplesException {
     long statementCount;
 
     if (rowCountIsValid) {
@@ -446,7 +430,7 @@
   /**
    * Map ARP anonymous node IDs to {@link BlankNode}s.
    */
-  private final Map blankNodeMap;
+  private final Map<String,BlankNode> blankNodeMap;
 
   private URL url;
 
@@ -461,7 +445,7 @@
   /**
    * The queue of buffers of triples generated by the RDF/XML parser.
    */
-  private LinkedList queue = new LinkedList();
+  private LinkedList<Triple[]> queue = new LinkedList<Triple[]>();
 
   /**
    * The number of statements parsed so far.
@@ -496,17 +480,13 @@
   /**
    * Sole constructor.
    */
-  Parser(URL url, Map blankNodeMap)
-  {
+  @SuppressWarnings("deprecation")
+  Parser(URL url, Map<String,BlankNode> blankNodeMap) {
     // Validate "url" parameter
-    if (url == null) {
-      throw new IllegalArgumentException("Null \"url\" parameter");
-    }
+    if (url == null) throw new IllegalArgumentException("Null \"url\" parameter");
 
     // Validate "blankNodeMap" parameter
-    if (blankNodeMap == null) {
-      throw new IllegalArgumentException("Null \"blankNodeMap\" parameter");
-    }
+    if (blankNodeMap == null) throw new IllegalArgumentException("Null \"blankNodeMap\" parameter");
 
     // Initialize fields
     this.url          = url;
@@ -531,8 +511,7 @@
   /**
    * @return the total number of statements in the file
    */
-  synchronized long waitForStatementTotal() throws TuplesException
-  {
+  synchronized long waitForStatementTotal() throws TuplesException {
     while (!complete) {
       checkForException();
 
@@ -555,8 +534,7 @@
    * Returns true if getStatementCount() would return the total number
    * of statements in the file.
    */
-  synchronized boolean isStatementCountTotal() throws TuplesException
-  {
+  synchronized boolean isStatementCountTotal() throws TuplesException {
     checkForException();
     return statementCountIsTotal;
   }
@@ -565,8 +543,7 @@
   // Method implementing Runnable
   //
 
-  public void run()
-  {
+  public void run() {
     Throwable t = null;
 
     // Parse the stream into RDF statements
@@ -577,13 +554,11 @@
       if (url.getPath().endsWith(".gz")) {
         // The file name ends with ".gz", so assume it's a gzip'ed file
         in = new GZIPInputStream(in);
-      }
-      else if (url.getPath().endsWith(".zip")) {
+      } else if (url.getPath().endsWith(".zip")) {
         // The file name ends with ".zip", so assume it's a zip'ed file
         in = new ZipInputStream(in);
 
-        // Assume first entry in the zip file is the one we want.
-        ZipEntry entry = ((ZipInputStream) in).getNextEntry();
+        ((ZipInputStream)in).getNextEntry();
       }
 
       arp.load(in, url.toString());
@@ -608,8 +583,7 @@
 
   public void statement(AResource subject,
                         AResource predicate,
-                        ALiteral object)
-  {
+                        ALiteral object) {
     if (logger.isDebugEnabled()) {
       logger.debug("Parsed " + subject + " " + predicate + " " + object + " from " + url);
     }
@@ -623,8 +597,7 @@
 
   public void statement(AResource subject,
                         AResource predicate,
-                        AResource object)
-  {
+                        AResource object) {
     if (logger.isDebugEnabled()) {
       logger.debug("Parsed " + subject + " " + predicate + " " + object + " from " + url);
     }
@@ -645,8 +618,7 @@
    *
    * @param e PARAMETER TO DO
    */
-  public synchronized void error(SAXParseException e)
-  {
+  public synchronized void error(SAXParseException e) {
     exception = e;
     logger.error("Error, " + e.getLineNumber() + ", column " +
                  e.getColumnNumber() + ": " + e.getMessage(), e);
@@ -657,8 +629,7 @@
    *
    * @param e PARAMETER TO DO
    */
-  public synchronized void fatalError(SAXParseException e)
-  {
+  public synchronized void fatalError(SAXParseException e) {
     exception = e;
     logger.error("Fatal error, line " + e.getLineNumber() + ", column " +
                  e.getColumnNumber() + ": " + e.getMessage(), e);
@@ -669,8 +640,7 @@
    *
    * @param e PARAMETER TO DO
    */
-  public void warning(SAXParseException e)
-  {
+  public void warning(SAXParseException e) {
     logger.warn("Warning, line " + e.getLineNumber() + ", column " +
                 e.getColumnNumber() + ": " + e.getMessage(), e);
   }
@@ -685,8 +655,7 @@
    * @param literal  the ARP literal
    * @return a JRDF literal
    */
-  private Literal toNode(ALiteral literal)
-  {
+  private Literal toNode(ALiteral literal) {
     URI type = null;
     if (literal.getDatatypeURI() != null) {
       try {
@@ -698,18 +667,14 @@
 
     String lang = literal.getLang();
     if (type == null) {
-      if (lang == null) {
-        lang = "";
-      }
-    }
-    else {
+      if (lang == null) lang = "";
+    } else {
       lang = null;
     }
 
     if (type == null) {
       return new LiteralImpl(literal.toString(), lang);
-    }
-    else {
+    } else {
       return new LiteralImpl(literal.toString(), type);
     }
   }
@@ -720,16 +685,13 @@
    * @param resource  the ARP resource.
    * @return the JRDF {@link URIReference} or {@link BlankNode}
    */
-  private Node toNode(AResource resource)
-  {
+  private Node toNode(AResource resource) {
     if (resource.isAnonymous()) {
       // Generate a blank node
       String anonymousID = resource.getAnonymousID();
 
-      BlankNode blankNode = (BlankNode) blankNodeMap.get(anonymousID);
-      if (blankNode == null) {
-        blankNode = new BlankNodeImpl();
-      }
+      BlankNode blankNode = blankNodeMap.get(anonymousID);
+      if (blankNode == null) blankNode = new BlankNodeImpl();
       assert blankNode != null;
 
       // Associate this new blank node with its anonymous ID and return it
@@ -739,8 +701,7 @@
       // Generate a URI reference
       try {
         return new URIReferenceImpl(new URI(resource.getURI().toString()));
-      }
-      catch (URISyntaxException e) {
+      } catch (URISyntaxException e) {
         throw new Error("ARP generated a malformed URI", e);
       }
     }
@@ -750,8 +711,7 @@
    * If an exception occurred in the parser, throws a TuplesException that
    * wraps the exception.
    */
-  private void checkForException() throws TuplesException
-  {
+  private void checkForException() throws TuplesException {
     if (exception != null) {
       queue.clear();
       headIndex = 0;
@@ -763,8 +723,7 @@
   /**
    * Returns a new triple from the queue or null if there are no more triples.
    */
-  Triple getTriple() throws TuplesException
-  {
+  Triple getTriple() throws TuplesException {
     if (headBuffer == null || headIndex >= headBuffer.length) {
       // Get another buffer from the queue.
       headIndex = 0;
@@ -784,8 +743,7 @@
     return triple;
   }
 
-  private synchronized Triple[] getBufferFromQueue() throws TuplesException
-  {
+  private synchronized Triple[] getBufferFromQueue() throws TuplesException {
     while (queue.isEmpty()) {
       checkForException();
       if (complete) {
@@ -852,8 +810,7 @@
     notifyAll();
   }
 
-  private synchronized void addBufferToQueue(Triple[] buffer)
-  {
+  private synchronized void addBufferToQueue(Triple[] buffer) {
     assert buffer != null;
     // Wait for the queue to drain a bit if it's too full
     while (queue.size() >= QUEUE_MAX_BUFFERS) {
@@ -871,8 +828,7 @@
   /**
    * Stops the thread.
    */
-  synchronized void abort()
-  {
+  synchronized void abort() {
     interrupt();
 
     // Clear the triples list and notify in case ARP uses an internal thread




More information about the Mulgara-svn mailing list