1 19 20 package com.hp.hpl.jena.ontology.impl; 23 24 25 26 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.rdf.model.Resource; 32 33 34 43 public class AllValuesFromRestrictionImpl 44 extends RestrictionImpl 45 implements AllValuesFromRestriction 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 AllValuesFromRestrictionImpl( n, eg ); 62 } 63 else { 64 throw new ConversionException( "Cannot convert node " + n + " to AllValuesFromRestriction"); 65 } 66 } 67 68 public boolean canWrap( Node node, EnhGraph eg ) { 69 Profile profile = (eg instanceof OntModel) ? ((OntModel) eg).getProfile() : null; 72 return (profile != null) && profile.isSupported( node, eg, AllValuesFromRestriction.class ); 73 } 74 }; 75 76 77 80 83 91 public AllValuesFromRestrictionImpl( Node n, EnhGraph g ) { 92 super( n, g ); 93 } 94 95 96 99 101 108 public void setAllValuesFrom( Resource cls ) { 109 setPropertyValue( getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM", cls ); 110 } 111 112 119 public Resource getAllValuesFrom() { 120 checkProfile( getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM" ); 121 Resource r = (Resource) getRequiredProperty( getProfile().ALL_VALUES_FROM() ).getObject(); 122 123 boolean currentStrict = ((OntModel) getModel()).strictMode(); 124 ((OntModel) getModel()).setStrictMode( true ); 125 126 try { 127 if (r.canAs( OntClass.class )) { 128 return (Resource) r.as( OntClass.class ); 130 } 131 else if (r.canAs( DataRange.class )) { 132 return (Resource) r.as( DataRange.class ); 134 } 135 else { 136 return r; 138 } 139 } 140 finally { 141 ((OntModel) getModel()).setStrictMode( currentStrict ); 142 } 143 } 144 145 152 public boolean hasAllValuesFrom( Resource cls ) { 153 return hasPropertyValue( getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM", cls ); 154 } 155 156 162 public void removeAllValuesFrom( Resource cls ) { 163 removePropertyValue( getProfile().ALL_VALUES_FROM(), "ALL_VALUES_FROM", cls ); 164 } 165 166 167 170 174 } 175 176 177 206 207 208 | Popular Tags |