/[cashew-s-editor]/cashews/src/nongnu/cashews/rdf/RDFHandler.java
ViewVC logotype

Diff of /cashews/src/nongnu/cashews/rdf/RDFHandler.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by gnu_andrew, Wed May 4 07:31:55 2005 UTC revision 1.4 by gnu_andrew, Thu May 19 10:51:48 2005 UTC
# Line 23  package nongnu.cashews.rdf; Line 23  package nongnu.cashews.rdf;
23    
24  import java.net.URI;  import java.net.URI;
25  import java.net.URISyntaxException;  import java.net.URISyntaxException;
 import java.util.HashSet;  
26  import java.util.Map;  import java.util.Map;
 import java.util.Set;  
27  import java.util.logging.Handler;  import java.util.logging.Handler;
28  import java.util.logging.Logger;  import java.util.logging.Logger;
29    
# Line 142  public class RDFHandler Line 140  public class RDFHandler
140    private PairStack<Subject,Predicate> currentState;    private PairStack<Subject,Predicate> currentState;
141    
142    /**    /**
    * The set of blank node IDs.  
    */  
   private Set<String> nodeIDs;  
   
   /**  
143     * Constructs a new <code>RDFHandler</code>, using the specified     * Constructs a new <code>RDFHandler</code>, using the specified
144     * handler for log messages.     * handler for log messages.
145     *     *
# Line 179  public class RDFHandler Line 172  public class RDFHandler
172      graph = new Graph();      graph = new Graph();
173      subjectURI = null;      subjectURI = null;
174      currentState = new PairStack<Subject,Predicate>();      currentState = new PairStack<Subject,Predicate>();
     nodeIDs = new HashSet<String>();  
175    }    }
176        
177    /**    /**
# Line 247  public class RDFHandler Line 239  public class RDFHandler
239                      value = attributes.getValue(RDF_NAMESPACE, "nodeID");                      value = attributes.getValue(RDF_NAMESPACE, "nodeID");
240                      if (value != null)                      if (value != null)
241                        {                        {
242                          object = new Blank(value);                          Blank blank = Blank.generateBlankNode(graph,value);
243                          rdfLogger.fine("Created object: " + object);                          if (blank != null)
244                              {
245                                object = blank;
246                                rdfLogger.fine("Created object: " + object);
247                              }
248                            else
249                              rdfLogger.severe("Duplicate blank node ID: " +
250                                               value);
251                        }                        }
252                    }                    }
253                  /* Check for a type */                  /* Check for a type */
# Line 281  public class RDFHandler Line 280  public class RDFHandler
280    {    {
281      try      try
282        {        {
283          return new RDFURI(new URI(value));          return new RDFURI(value);
284        }        }
285      catch (URISyntaxException e)      catch (URISyntaxException e)
286        {        {
# Line 432  public class RDFHandler Line 431  public class RDFHandler
431              if (value != null)              if (value != null)
432                {                {
433                  attributes.remove(RDF_NAMESPACE, "nodeID");                  attributes.remove(RDF_NAMESPACE, "nodeID");
434                  boolean added = nodeIDs.add(value);                  Blank blank = Blank.generateBlankNode(graph,value);
435                  if (added)                  if (blank != null)
436                    subject = new Blank(value);                    subject = blank;
437                  else                  else
438                    rdfLogger.severe("Duplicate blank node ID: " + value);                    rdfLogger.severe("Duplicate blank node ID: " + value);
439                }                }
440              else              else
441                subject = new Blank(generateBlankID());                subject = Blank.generateBlankNode(graph);
442            }            }
443        }        }
444      if (subject == null)      if (subject == null)
# Line 479  public class RDFHandler Line 478  public class RDFHandler
478    }    }
479    
480    /**    /**
    * Generate an ID for a blank node.  
    *  
    * @return a blank node ID.  
    */  
   private String generateBlankID()  
   {  
     boolean added = false;  
     String randomID;  
     do  
       {  
         randomID = Long.toString(Math.round(Math.random() * Long.MAX_VALUE));  
         added = nodeIDs.add(randomID);  
       } while (!added);  
     return randomID;  
   }  
   
   /**  
481     * Handle the end of a subject node, including one that is     * Handle the end of a subject node, including one that is
482     * nested inside another.  Subject nodes take two forms, so     * nested inside another.  Subject nodes take two forms, so
483     * it becomes necessary to have common handling for these.     * it becomes necessary to have common handling for these.

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26