Source for file ResResource.php

Documentation is available at ResResource.php

  1. <?PHP
  2. /**
  3. * ----------------------------------------------------------------------------------
  4. * Class: ResResource
  5. * ----------------------------------------------------------------------------------
  6. * @package resModel
  7. ***/
  8.  
  9. /**
  10. * An RDF Resource.
  11. * Resource instances, when created, are associated with a specific model. They support a
  12. * range of methods, such as getProperty() and addProperty() which will access or modify
  13. * that model. This enables the programmer to write code in a compact and easy style.
  14. *
  15. * <BR><BR>History:<UL>
  16. * <LI>10-01-2004 : First version of this class.</LI>
  17. *
  18. * @version V0.9.1
  19. * @author Daniel Westphal <mail at d-westphal dot de>
  20. *
  21. *
  22. * @package resModel
  23. * @access public
  24. ***/
  25. class ResResource extends Resource
  26. {
  27. /**
  28. * Holds a reference to the associated model
  29. * @var ResModel
  30. * @access private
  31. */
  32. var $model;
  33. /**
  34. * Is true, if this resource is an anonymous node.
  35. * @var boolean
  36. * @access private
  37. */
  38. var $isAnon;
  39. /**
  40. * Constructor
  41. * You can supply a uri
  42. *
  43. * @param string $uri
  44. * @access public
  45. */
  46. function ResResource($uri)
  47. {
  48. parent::Resource($uri);
  49. $this->isAnon = ($uri === null);
  50. }
  51. /**
  52. * Sets the reference to the assocoated model.
  53. *
  54. * @param object Model $model
  55. * @access public
  56. */
  57. function setAssociatedModel(& $model)
  58. {
  59. $this->model=& $model;
  60. if ($this->isAnon)
  61. $this->uri=$this->model->getUniqueResourceURI(BNODE_PREFIX);
  62. }
  63. /**
  64. * Get the reference to the assocoated model.
  65. *
  66. * @return object Model $model
  67. * @access public
  68. */
  69. function getAssociatedModel()
  70. {
  71. return $this->model;
  72. }
  73. /**
  74. * Sets the URI of this resource
  75. *
  76. * @param string $uri
  77. * @access public
  78. */
  79. function setURI($uri)
  80. {
  81. $this->uri = $uri;
  82. }
  83. /**
  84. * Add a property to this resource.
  85. * A statement with this resource as the subject, p as the predicate and o
  86. * as the object is added to the model associated with this resource.
  87. *
  88. * @param ResResource $property
  89. * @param ResResource/ResLiteral $object
  90. * @return object ResResource
  91. * @access public
  92. */
  93. function addProperty($property,$object)
  94. {
  95. $this->model->add(new Statement($this,$property,$object));
  96.  
  97. return $this;
  98. }
  99. /**
  100. * List all the values with the property p as statements in an array.
  101. *
  102. * @param ResResource $property
  103. * @return ResIterator
  104. * @access public
  105. */
  106. function listProperties($property = null)
  107. {
  108. return $this->model->find($this,$property,null);
  109. }
  110. /**
  111. * Answer some statement (this, p, O) in the associated model.
  112. * If there are several such statements, any one of them may be returned.
  113. * If no such statements exist, null is returned.
  114. *
  115. * @param ResResource $property
  116. * @return object ResResource
  117. * @access public
  118. */
  119. function getProperty($property)
  120. {
  121. return $this->model->getProperty($this,$property);
  122. }
  123. /**
  124. * Determine whether this resource has any values for a given property.
  125. *
  126. * @param ResResource $property
  127. * @param ResResource $value
  128. * @return object ResResource
  129. * @access public
  130. */
  131. function hasProperty($property, $value = null)
  132. {
  133. $ret= $this->model->findFirstMatchingStatement($this,$property,$value);
  134. return ($ret!==null);
  135. }
  136. /**
  137. * Determine whether this resource is an anonymous resource
  138. *
  139. * @return boolean
  140. * @access public
  141. */
  142. function getIsAnon()
  143. {
  144. return $this->isAnon;
  145. }
  146. /**
  147. * Set whether this resource is an anonymous resource
  148. *
  149. * @param boolean
  150. * @access public
  151. */
  152. function setIsAnon($isAnon)
  153. {
  154. $this->isAnon=$isAnon;
  155. }
  156. /**
  157. * Checks if the resource equals another resource.
  158. * Two resources are equal, if they have the same URI
  159. *
  160. * @access public
  161. * @param object resource $that
  162. * @return boolean
  163. */
  164. function equals ($that)
  165. {
  166. if (is_a($that,'ResLiteral'))
  167. return $that->equals($this);
  168. return ($that!==null && ($this->getURI() == $that->getURI()));
  169. }
  170. /**
  171. * Delete all the statements with predicate p for this resource from
  172. * its associated model.
  173. *
  174. * @access public
  175. * @param object resource $property
  176. * @return object ResResource
  177. */
  178. function removeAll($property = null)
  179. {
  180. foreach ($this->model->find($this,$property,null) as $statement)
  181. {
  182. $this->model->remove($statement);
  183. }
  184. return $this;
  185. }
  186. /**
  187. * Delete all the properties for this resource from the associated model.
  188. *
  189. * @access public
  190. * @return object ResResource
  191. */
  192. function removeProperties()
  193. {
  194. $this->removeAll();
  195. return $this;
  196. }
  197. }
  198. ?>

Documentation generated on Fri, 17 Dec 2004 16:18:03 +0100 by phpDocumentor 1.3.0RC3