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.NodeIteratorImpl; 28 import com.hp.hpl.jena.util.iterator.*; 29 import com.hp.hpl.jena.ontology.*; 30 import com.hp.hpl.jena.ontology.daml.*; 31 32 33 34 40 public class PropertyAccessorImpl 41 implements PropertyAccessor 42 { 43 46 47 50 51 54 55 protected Property m_property = null; 56 57 58 protected OntResource m_val = null; 59 60 61 62 65 72 public PropertyAccessorImpl( Property property, OntResource val ) { 73 m_property = property; 74 m_val = val; 75 } 76 77 78 79 82 87 public Property getProperty() { 88 return m_property; 89 } 90 91 92 98 public int count() { 99 return m_val.getCardinality( getProperty() ); 100 } 101 102 103 115 public NodeIterator getAll() { 116 return new NodeIteratorImpl( UniqueExtendedIterator.create( m_val.listPropertyValues( getProperty() ) ), null ); 117 } 118 119 120 128 public RDFNode get() { 129 return m_val.getPropertyValue( getProperty() ).as( DAMLCommon.class ); 130 } 131 132 133 142 public DAMLList getList() { 143 RDFNode n = get(); 144 return (n == null) ? null : (DAMLList) n.as( DAMLList.class ); 145 } 146 147 148 154 public DAMLCommon getDAMLValue() { 155 NodeIterator i = null; 156 try { 157 for (i = getAll(); i.hasNext(); ) { 158 RDFNode n = (RDFNode) i.next(); 159 160 if (n.canAs( DAMLCommon.class )) { 161 return (DAMLCommon) n.as( DAMLCommon.class ); 162 } 163 } 164 165 return null; 167 } 168 finally { 169 if (i != null) { 170 i.close(); 171 } 172 } 173 } 174 175 176 181 public void add( RDFNode value ) { 182 m_val.addProperty( getProperty(), value ); 183 } 184 185 186 191 public void remove( RDFNode value ) { 192 m_val.removeProperty( getProperty(), value ); 193 } 194 195 196 204 public boolean hasValue( RDFNode value ) { 205 return m_val.hasProperty( getProperty(), value ); 206 } 207 208 209 210 213 214 215 219 220 } 221 222 223 252 253 | Popular Tags |