1 18 19 package com.hp.hpl.jena.ontology.daml.impl; 22 23 24 import com.hp.hpl.jena.rdf.model.*; 27 import com.hp.hpl.jena.rdf.model.impl.RDFListImpl; 28 import com.hp.hpl.jena.enhanced.*; 29 import com.hp.hpl.jena.graph.*; 30 import com.hp.hpl.jena.ontology.*; 31 import com.hp.hpl.jena.ontology.daml.*; 32 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 33 import com.hp.hpl.jena.vocabulary.*; 34 35 36 37 38 51 public class DAMLListImpl 52 extends RDFListImpl 53 implements DAMLList 54 { 55 58 59 62 67 public static Implementation factory = new Implementation() { 68 public EnhNode wrap( Node n, EnhGraph eg ) { 69 if (canWrap( n, eg )) { 70 return new DAMLListImpl( n, eg ); 71 } 72 else { 73 throw new ConversionException( "Cannot convert node " + n.toString() + " to DAMLList" ); 74 } 75 } 76 77 public boolean canWrap( Node node, EnhGraph eg ) { 78 Graph g = eg.asGraph(); 80 81 return node.equals( DAML_OIL.nil.asNode() ) || 83 g.find( node, DAML_OIL.first.asNode(), Node.ANY ).hasNext() || 84 g.find( node, DAML_OIL.rest.asNode(), Node.ANY ).hasNext() || 85 g.find( node, RDF.type.asNode(), DAML_OIL.List.asNode() ).hasNext(); 86 } 87 }; 88 89 90 91 94 95 96 99 107 public DAMLListImpl( Node n, EnhGraph g ) { 108 super( n, g ); 109 } 110 111 112 113 114 117 public Resource listType() { return DAML_OIL.List; } 119 public Resource listNil() { return DAML_OIL.nil; } 120 public Property listFirst() { return DAML_OIL.first; } 121 public Property listRest() { return DAML_OIL.rest; } 122 public Class listAbstractionClass() { return DAMLList.class; } 123 124 125 130 public ExtendedIterator getAll() { 131 return iterator(); 132 } 133 134 135 147 public RDFNode getFirst() { 148 return getHead(); 149 } 150 151 152 163 public DAMLList getRest() { 164 return (DAMLList) getTail().as( DAMLList.class ); 165 } 166 167 168 174 public int getCount() { 175 return size(); 176 } 177 178 179 185 public void setFirst( DAMLCommon value ) { 186 setHead( value ); 187 } 188 189 190 196 public void setRest( DAMLList tail ) { 197 setTail( tail ); 198 } 199 200 201 205 public void setRestNil() { 206 setRest( getNil() ); 207 } 208 209 210 219 public DAMLList cons( DAMLCommon value ) { 220 return (DAMLList) super.cons( value ).as( DAMLList.class ); 221 } 222 223 224 229 public DAMLList getNil() { 230 return (DAMLList) listNil().as( DAMLList.class ); 231 } 232 233 234 240 public boolean isNil( Resource resource ) { 241 return resource.equals( listNil() ); 242 } 243 244 245 250 public DAMLList findLast() { 251 return (DAMLList) findElement( true, 0 ).as( DAMLList.class ); 252 } 253 254 255 265 public DAMLCommon getItem( int i ) { 266 return (DAMLCommon) get( i ).as( DAMLCommon.class ); 267 } 268 269 270 273 274 275 276 280 281 } 282 283 284 313 314 | Popular Tags |