PageRenderTime 25ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/s3db3.5.10/pearlib/rdfapi-php/api/resModel/ResResource.php

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