1 19 20 package com.hp.hpl.jena.ontology.impl; 23 24 25 26 import com.hp.hpl.jena.graph.*; 29 import com.hp.hpl.jena.enhanced.*; 30 import com.hp.hpl.jena.ontology.*; 31 import com.hp.hpl.jena.rdf.model.*; 32 33 34 43 public class RestrictionImpl 44 extends OntClassImpl 45 implements Restriction 46 { 47 50 53 58 public static Implementation factory = new Implementation() { 59 public EnhNode wrap( Node n, EnhGraph eg ) { 60 if (canWrap( n, eg )) { 61 return new RestrictionImpl( n, eg ); 62 } 63 else { 64 throw new ConversionException( "Cannot convert node " + n + " to Restriction"); 65 } 66 } 67 68 public boolean canWrap( Node node, EnhGraph eg ) { 69 Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null; 71 return (profile != null) && profile.isSupported( node, eg, Restriction.class ); 72 } 73 }; 74 75 76 79 82 90 public RestrictionImpl( Node n, EnhGraph g ) { 91 super( n, g ); 92 } 93 94 95 98 100 106 public void setOnProperty( Property prop ) { 107 setPropertyValue( getProfile().ON_PROPERTY(), "ON_PROPERTY", prop ); 108 } 109 110 117 public OntProperty getOnProperty() { 118 return (OntProperty) objectAs( getProfile().ON_PROPERTY(), "ON_PROPERTY", OntProperty.class ); 119 } 120 121 127 public boolean onProperty( Property prop ) { 128 return hasPropertyValue( getProfile().ON_PROPERTY(), "ON_PROPERTY", prop ); 129 } 130 131 136 public void removeOnProperty( Property prop ) { 137 removePropertyValue( getProfile().ON_PROPERTY(), "ON_PROPERTY", prop ); 138 } 139 140 141 147 public AllValuesFromRestriction asAllValuesFromRestriction() { 148 return (AllValuesFromRestriction) as( AllValuesFromRestriction.class ); 149 } 150 151 157 public SomeValuesFromRestriction asSomeValuesFromRestriction() { 158 return (SomeValuesFromRestriction) as( SomeValuesFromRestriction.class ); 159 } 160 161 167 public HasValueRestriction asHasValueRestriction() { 168 return (HasValueRestriction) as( HasValueRestriction.class ); 169 } 170 171 177 public CardinalityRestriction asCardinalityRestriction() { 178 return (CardinalityRestriction) as( CardinalityRestriction.class ); 179 } 180 181 187 public MinCardinalityRestriction asMinCardinalityRestriction() { 188 return (MinCardinalityRestriction) as( MinCardinalityRestriction.class ); 189 } 190 191 197 public MaxCardinalityRestriction asMaxCardinalityRestriction() { 198 return (MaxCardinalityRestriction) as( MaxCardinalityRestriction.class ); 199 } 200 201 202 204 209 public boolean isAllValuesFromRestriction() { 210 checkProfile( getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM" ); 211 return hasProperty( getProfile().ALL_VALUES_FROM() ); 212 } 213 214 219 public boolean isSomeValuesFromRestriction() { 220 checkProfile( getProfile().SOME_VALUES_FROM(), "SOME_VALUES_FROM" ); 221 return hasProperty( getProfile().SOME_VALUES_FROM() ); 222 } 223 224 229 public boolean isHasValueRestriction() { 230 checkProfile( getProfile().HAS_VALUE(), "HAS_VALUE" ); 231 return hasProperty( getProfile().HAS_VALUE() ); 232 } 233 234 241 public boolean isCardinalityRestriction() { 242 checkProfile( getProfile().CARDINALITY(), "CARDINALITY" ); 243 return hasProperty( getProfile().CARDINALITY() ); 244 } 245 246 253 public boolean isMinCardinalityRestriction() { 254 checkProfile( getProfile().MIN_CARDINALITY(), "MIN_CARDINALITY" ); 255 return hasProperty( getProfile().MIN_CARDINALITY() ); 256 } 257 258 265 public boolean isMaxCardinalityRestriction() { 266 checkProfile( getProfile().MAX_CARDINALITY(), "MAX_CARDINALITY" ); 267 return hasProperty( getProfile().MAX_CARDINALITY() ); 268 } 269 270 271 273 280 public AllValuesFromRestriction convertToAllValuesFromRestriction( Resource cls ) { 281 setPropertyValue( getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM", cls ); 282 return (AllValuesFromRestriction) as( AllValuesFromRestriction.class ); 283 } 284 285 292 public SomeValuesFromRestriction convertToSomeValuesFromRestriction( Resource cls ) { 293 setPropertyValue( getProfile().SOME_VALUES_FROM(), "SOME_VALUES_FROM", cls ); 294 return (SomeValuesFromRestriction) as( SomeValuesFromRestriction.class ); 295 } 296 297 304 public HasValueRestriction convertToHasValueRestriction( RDFNode value ) { 305 setPropertyValue( getProfile().HAS_VALUE(), "HAS_VALUE", value ); 306 return (HasValueRestriction) as( HasValueRestriction.class ); 307 } 308 309 315 public CardinalityRestriction convertToCardinalityRestriction( int cardinality ) { 316 setPropertyValue( getProfile().CARDINALITY(), "CARDINALITY", getModel().createTypedLiteral( cardinality ) ); 317 return (CardinalityRestriction) as( CardinalityRestriction.class ); 318 } 319 320 326 public MinCardinalityRestriction convertToMinCardinalityRestriction( int cardinality ) { 327 setPropertyValue( getProfile().MIN_CARDINALITY(), "MIN_CARDINALITY", getModel().createTypedLiteral( cardinality ) ); 328 return (MinCardinalityRestriction) as( MinCardinalityRestriction.class ); 329 } 330 331 337 public MaxCardinalityRestriction convertToMaxCardinalityRestriction( int cardinality ) { 338 setPropertyValue( getProfile().MAX_CARDINALITY(), "MAX_CARDINALITY", getModel().createTypedLiteral( cardinality ) ); 339 return (MaxCardinalityRestriction) as( MaxCardinalityRestriction.class ); 340 } 341 342 343 346 350 } 351 352 353 382 383 384 | Popular Tags |