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 |
|
|
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 |
* |
* |
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 |
/** |
/** |
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 */ |
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 |
{ |
{ |
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) |
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. |