1 19 20 package com.hp.hpl.jena.ontology.impl; 23 24 25 import java.util.Iterator ; 28 29 import com.hp.hpl.jena.enhanced.*; 30 import com.hp.hpl.jena.graph.Node; 31 import com.hp.hpl.jena.ontology.*; 32 import com.hp.hpl.jena.rdf.model.*; 33 import com.hp.hpl.jena.util.iterator.ExtendedIterator; 34 35 36 45 public class EnumeratedClassImpl 46 extends OntClassImpl 47 implements EnumeratedClass 48 { 49 52 55 60 public static Implementation factory = new Implementation() { 61 public EnhNode wrap( Node n, EnhGraph eg ) { 62 if (canWrap( n, eg )) { 63 return new EnumeratedClassImpl( n, eg ); 64 } 65 else { 66 throw new ConversionException( "Cannot convert node " + n + " to EnumeratedClass"); 67 } 68 } 69 70 public boolean canWrap( Node node, EnhGraph eg ) { 71 Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null; 73 return (profile != null) && 74 profile.isSupported( node, eg, OntClass.class ) && 75 eg.asGraph().contains( node, profile.ONE_OF().asNode(), Node.ANY ); 76 } 77 }; 78 79 80 83 86 94 public EnumeratedClassImpl( Node n, EnhGraph g ) { 95 super( n, g ); 96 } 97 98 99 102 104 110 public void setOneOf( RDFList en ) { 111 setPropertyValue( getProfile().ONE_OF(), "ONE_OF", en ); 112 } 113 114 119 public void addOneOf( Resource res ) { 120 addListPropertyValue( getProfile().ONE_OF(), "ONE_OF", res ); 121 } 122 123 129 public void addOneOf( Iterator individuals ) { 130 while( individuals.hasNext() ) { 131 addOneOf( (Resource) individuals.next() ); 132 } 133 } 134 135 140 public RDFList getOneOf() { 141 return (RDFList) objectAs( getProfile().ONE_OF(), "ONE_OF", RDFList.class ); 142 } 143 144 150 public ExtendedIterator listOneOf() { 151 return getOneOf().iterator().mapWith( new AsMapper( OntResource.class ) ); 152 } 153 154 161 public boolean hasOneOf( Resource res ) { 162 return getOneOf().contains( res ); 163 } 164 165 171 public void removeOneOf( Resource res ) { 172 setOneOf( getOneOf().remove( res ) ); 173 } 174 175 176 177 180 184 } 185 186 187 216 217 218 | Popular Tags |