1 5 6 package com.hp.hpl.jena.db.impl; 7 8 import java.net.UnknownHostException ; 9 import java.rmi.server.UID ; 10 11 import com.hp.hpl.jena.graph.*; 12 import com.hp.hpl.jena.util.iterator.*; 13 import com.hp.hpl.jena.vocabulary.DB; 14 15 16 32 public abstract class DBProp { 33 34 protected SpecializedGraph graph = null; 35 protected Node self = null; 36 37 public DBProp( SpecializedGraph g) { 38 graph = g; 39 self = generateNodeURI(); 40 } 41 42 public DBProp( SpecializedGraph g, Node n) { 43 graph = g; 44 self = n; 45 } 46 47 public Node getNode() { return self; } 48 49 53 protected static SpecializedGraph.CompletionFlag newComplete() 54 { return new SpecializedGraph.CompletionFlag(); } 55 56 protected void putPropString( Node_URI predicate, String value) { 57 putPropNode( predicate, Node.createLiteral( value ) ); 58 } 59 60 protected void putPropNode( Node_URI predicate, Node node) { 61 graph.add( Triple.create( self, predicate, node ), newComplete() ); 62 } 63 64 protected String getPropString( Node_URI predicate) { 65 ClosableIterator it = graph.find(self, predicate, null, newComplete() ); 66 if( !it.hasNext() ) { 67 it.close(); 68 return null; 69 } 70 Node result = ((Triple)it.next()).getObject(); 71 it.close(); 72 return result.getLiteral().getLexicalForm(); 73 } 74 75 protected void remove() { 76 SpecializedGraph.CompletionFlag complete = newComplete(); 77 ClosableIterator it = graph.find( self, null, null, complete); 78 while( it.hasNext() ) graph.delete( (Triple) it.next(), complete ); 79 it.close(); 80 self = null; 81 graph = null; 82 } 83 84 void showGraph() 85 { 86 SpecializedGraph.CompletionFlag complete = newComplete(); 87 ExtendedIterator it = graph.find( self, null, null, complete ); 88 while (it.hasNext()) System.err.println( ">> " + it.next() ); 89 } 90 91 public static ExtendedIterator listTriples( SpecializedGraph g, Node self ) { 92 return g.find( self, null, null, newComplete() ); 94 } 95 96 protected static Node findProperty( Graph graph, Node_URI predicate ) { 97 ClosableIterator it = graph.find( null, predicate, null ); 98 Node result = null; 99 if( it.hasNext() ) result = ((Triple) it.next()).getObject(); 100 it.close(); 101 return result; 102 } 103 104 public static String generateUniqueID() { 105 UID uid = new UID (); 106 String hostname; 107 try { 108 hostname = java.net.InetAddress.getLocalHost().getHostAddress().toString(); 109 } catch (UnknownHostException e) { 110 hostname = "localhost"; 111 } 112 return (hostname + uid.toString()).replace('.','_').replace(':','_').replace('-','_'); 113 } 114 115 public static Node generateNodeURI() { 116 String generateUniqueID = null; 117 return Node.createURI( DB.uri + generateUniqueID() ); 118 } 119 120 121 } 122 123 | Popular Tags |