1 31 32 package com.hp.hpl.jena.rdf.model.impl; 33 34 import com.hp.hpl.jena.rdf.model.*; 35 import com.hp.hpl.jena.vocabulary.RDF; 36 import com.hp.hpl.jena.graph.*; 37 import com.hp.hpl.jena.enhanced.*; 38 39 44 public class AltImpl extends ContainerImpl implements Alt { 45 46 final static public Implementation factory = new Implementation() { 47 public boolean canWrap( Node n, EnhGraph eg ) 48 { return true; } 49 public EnhNode wrap(Node n,EnhGraph eg) { 50 return new AltImpl(n,eg); 51 } 52 }; 53 54 55 public AltImpl( ModelCom model ) 56 { super( model ); } 57 58 public AltImpl( String uri, ModelCom model ) { 59 super( uri, model ); 60 } 61 62 public AltImpl( Resource r, ModelCom m ) { 63 super( r, m ); 64 } 65 66 public AltImpl(Node n, EnhGraph g) { 67 super( n, g ); 68 } 69 70 71 72 private Statement needDefaultStatement() 73 { 74 Statement stmt = getDefaultStatement(); 75 if (stmt == null) throw new AltHasNoDefaultException( this ); 76 return stmt; 77 } 78 79 public RDFNode getDefault() { 80 return needDefaultStatement().getObject(); 81 } 82 83 public Resource getDefaultResource() { 84 return needDefaultStatement().getResource(); 85 } 86 87 public Literal getDefaultLiteral() { 88 return needDefaultStatement().getLiteral(); 89 } 90 91 public boolean getDefaultBoolean() { 92 return needDefaultStatement().getBoolean(); 93 } 94 95 public byte getDefaultByte() { 96 return needDefaultStatement().getByte(); 97 } 98 99 public short getDefaultShort() { 100 return needDefaultStatement().getShort(); 101 } 102 103 public int getDefaultInt() { 104 return needDefaultStatement().getInt(); 105 } 106 107 public long getDefaultLong() { 108 return needDefaultStatement().getLong(); 109 } 110 111 public char getDefaultChar() { 112 return needDefaultStatement().getChar(); 113 } 114 115 public float getDefaultFloat() { 116 return needDefaultStatement().getFloat(); 117 } 118 119 public double getDefaultDouble() { 120 return needDefaultStatement().getDouble(); 121 } 122 123 public String getDefaultString() { 124 return needDefaultStatement().getString(); 125 } 126 127 public String getDefaultLanguage() { 128 return needDefaultStatement().getLanguage(); 129 } 130 131 public Resource getDefaultResource(ResourceF f) { 132 return needDefaultStatement().getResource(); 133 } 134 135 public Object getDefaultObject(ObjectF f) { 136 return needDefaultStatement().getObject( f ); 137 } 138 139 public Alt getDefaultAlt() { 140 return needDefaultStatement().getAlt(); 141 } 142 143 public Bag getDefaultBag() { 144 return needDefaultStatement().getBag(); 145 } 146 147 public Seq getDefaultSeq() { 148 return needDefaultStatement().getSeq(); 149 } 150 151 public Alt setDefault(RDFNode o) { 152 Statement stmt = getDefaultStatement(); 153 if (stmt != null) getModel().remove( stmt ); 154 getModel().add( this, RDF.li(1), o ); 155 return this; 156 } 157 158 public Alt setDefault(boolean o) { 159 return setDefault( String.valueOf( o ) ); 160 } 161 162 public Alt setDefault(long o) { 163 return setDefault( String.valueOf( o ) ); 164 } 165 166 public Alt setDefault(char o) { 167 return setDefault( String.valueOf( o ) ); 168 } 169 170 public Alt setDefault(float o) { 171 return setDefault( String.valueOf( o ) ); 172 } 173 174 public Alt setDefault(double o) { 175 return setDefault( String.valueOf( o ) ); 176 } 177 178 public Alt setDefault(Object o) { 179 return setDefault( String.valueOf( o ) ); 180 } 181 182 public Alt setDefault(String o) { 183 return setDefault( o, "" ); 184 } 185 186 public Alt setDefault(String o, String l) { 187 return setDefault( new LiteralImpl( Node.createLiteral( o,l, false ), getModelCom()) ); 188 } 189 190 protected Statement getDefaultStatement() 191 { 192 StmtIterator iter = getModel().listStatements( this, RDF.li(1), (RDFNode) null ); 193 try { return iter.hasNext() ? iter.nextStatement() : null; } 194 finally { iter.close(); } 195 } 196 197 } | Popular Tags |