1 6 7 package com.hp.hpl.jena.rdf.model.impl; 8 9 import com.hp.hpl.jena.graph.Node; 10 import com.hp.hpl.jena.rdf.model.*; 11 import com.hp.hpl.jena.shared.JenaException; 12 13 19 public abstract class StatementBase 20 { 21 protected final ModelCom model; 22 23 protected StatementBase( ModelCom model ) 24 { 25 if (model == null) throw new JenaException( "Statement models must no be null" ); 26 this.model = model; 27 } 28 29 public Model getModel() 30 { 31 return model; 32 } 33 34 39 protected abstract StatementImpl replace( RDFNode n ); 40 41 45 public abstract Literal getLiteral(); 46 47 public abstract Resource getResource(); 48 49 public abstract Resource getSubject(); 50 51 public abstract Property getPredicate(); 52 53 public abstract RDFNode getObject(); 54 55 protected StatementImpl stringReplace(String s, String lang, 56 boolean wellFormed) 57 { 58 return replace(new LiteralImpl(Node.createLiteral(s, lang, wellFormed), 59 model)); 60 } 61 62 68 protected StatementImpl stringReplace( String s ) 69 { 70 return stringReplace( s, "", false ); 71 } 72 73 public Statement changeObject( boolean o ) 74 { 75 return stringReplace( String.valueOf( o ) ); 76 } 77 78 public Statement changeObject( long o ) 79 { 80 return stringReplace( String.valueOf( o ) ); 81 } 82 83 public Statement changeObject( char o ) 84 { 85 return stringReplace( String.valueOf( o ) ); 86 } 87 88 public Statement changeObject( float o ) 89 { 90 return stringReplace( String.valueOf( o ) ); 91 } 92 93 public Statement changeObject( double o ) 94 { 95 return stringReplace( String.valueOf( o ) ); 96 } 97 98 public Statement changeObject( String o ) 99 { 100 return stringReplace( String.valueOf( o ) ); 101 } 102 103 public Statement changeObject( String o, boolean wellFormed ) 104 { 105 return stringReplace( String.valueOf( o ), "", wellFormed ); 106 } 107 108 public Statement changeObject( String o, String l ) 109 { 110 return stringReplace( String.valueOf( o ), l, false ); 111 } 112 113 public Statement changeObject( String o, String l, boolean wellFormed ) 114 { 115 return stringReplace( String.valueOf( o ), l, wellFormed ); 116 } 117 118 public Statement changeObject( RDFNode o ) 119 { 120 return replace( o ); 121 } 122 123 public Statement changeObject( Object o ) 124 { 125 return o instanceof RDFNode 126 ? replace( (RDFNode) o ) 127 : stringReplace( o.toString() ); 128 } 129 130 public boolean getBoolean() 131 { 132 return getLiteral().getBoolean(); 133 } 134 135 public byte getByte() 136 { 137 return getLiteral().getByte(); 138 } 139 140 public short getShort() 141 { 142 return getLiteral().getShort(); 143 } 144 145 public int getInt() 146 { 147 return getLiteral().getInt(); 148 } 149 150 public long getLong() 151 { 152 return getLiteral().getLong(); 153 } 154 155 public char getChar() 156 { 157 return getLiteral().getChar(); 158 } 159 160 public float getFloat() 161 { 162 return getLiteral().getFloat(); 163 } 164 165 public double getDouble() 166 { 167 return getLiteral().getDouble(); 168 } 169 170 public String getString() 171 { 172 return getLiteral().getLexicalForm(); 173 } 174 175 178 protected Resource mustBeResource(RDFNode n) 179 { 180 if (n instanceof Resource) 181 return (Resource) n; 182 else 183 throw new ResourceRequiredException(n); 184 } 185 186 public String getLanguage() 187 { 188 return getLiteral().getLanguage(); 189 } 190 191 public boolean getWellFormed() 192 { 193 return getLiteral().getWellFormed(); 194 } 195 196 200 public String toString() 201 { 202 return 203 "[" 204 + getSubject().toString() 205 + ", " + getPredicate().toString() 206 + ", " + objectString( getObject() ) 207 + "]"; 208 } 209 210 213 protected String objectString( RDFNode object ) 214 { 215 return object.asNode().toString( null, true ); 216 } 217 218 } 219 220 243 | Popular Tags |