1 6 7 package com.hp.hpl.jena.rdf.model.impl; 8 9 import com.hp.hpl.jena.enhanced.*; 10 import com.hp.hpl.jena.graph.*; 11 import com.hp.hpl.jena.rdf.model.*; 12 13 14 17 18 public class ReifiedStatementImpl extends ResourceImpl implements ReifiedStatement 19 { 20 21 protected Statement statement; 22 23 27 28 private ReifiedStatementImpl( ModelCom m, String uri, Statement s ) 29 { 30 super( uri, m ); 31 assertStatement( s ); 32 } 33 34 protected ReifiedStatementImpl( EnhGraph m, Node n, Statement s ) 35 { 36 super( n, m ); 37 assertStatement( s ); 38 } 39 40 private void assertStatement( Statement s ) 41 { 42 statement = s; 43 } 44 45 49 public Statement getStatement() 50 { return statement; } 51 52 static final public Implementation reifiedStatementFactory = new Implementation() 53 { 54 59 public EnhNode wrap( Node n, EnhGraph eg ) 60 { 61 Triple x = getTriple( eg, n ); 62 if (x == null) throw new DoesNotReifyException( n ); 63 Statement st = StatementImpl.toStatement( x, (ModelCom) eg ); 64 return new ReifiedStatementImpl( eg, n, st ); 65 } 66 67 74 public boolean canWrap( Node n, EnhGraph eg ) 75 { return getTriple( eg, n ) != null; } 76 77 83 private Triple getTriple( EnhGraph eg, Node n ) 84 { return eg.asGraph().getReifier().getTriple( n ); } 85 }; 86 87 90 protected Reifier getReifier() 91 { return getModel().getGraph().getReifier(); } 92 93 public boolean isValid() 94 { return getModel().getGraph().getReifier().getTriple( this.asNode() ) != null; } 95 96 101 private ReifiedStatementImpl cache() 102 { 103 getReifier().reifyAs( this.asNode(), statement.asTriple() ); 104 return this; 105 } 106 107 111 public static ReifiedStatement create( Statement s ) 112 { return create( (ModelCom) s.getModel(), (String ) null, s ); } 113 114 118 public static ReifiedStatementImpl create( ModelCom m, String uri, Statement s ) 119 { return new ReifiedStatementImpl( m, uri, s ).cache(); } 120 121 public static ReifiedStatementImpl create( EnhGraph eg, Node n, Statement s ) 122 { return new ReifiedStatementImpl( eg, n, s ).cache(); } 123 124 public String toString() 125 { return super.toString() + "=>" + statement; } 126 } 127 128 157 | Popular Tags |