Source for file ResSeq.php

Documentation is available at ResSeq.php

  1. <?PHP
  2. // ----------------------------------------------------------------------------------
  3. // Class: ResSeq
  4. // ----------------------------------------------------------------------------------
  5.  
  6.  
  7.  
  8. /**
  9. * This interface defines methods for accessing RDF Sequence resources.
  10. * These methods operate on the RDF statements contained in a model.
  11. *
  12. * <BR><BR>History:<UL>
  13. * <LI>10-01-2004 : First version of this class.</LI>
  14. *
  15. * @version V0.9.1
  16. * @author Daniel Westphal <mail at d-westphal dot de>
  17. *
  18. * @package resModel
  19. * @access public
  20. ***/
  21. class ResSeq extends ResContainer
  22. {
  23. /**
  24. * Constructor
  25. * You can supply a URI
  26. *
  27. * @param string $uri
  28. * @access public
  29. */
  30. function ResSeq($uri = null)
  31. {
  32. parent::ResContainer($uri);
  33. $this->containerType=new ResResource(RDF_NAMESPACE_URI.RDF_SEQ);
  34. }
  35. /**
  36. * Insert a new member into the sequence at the specified position.
  37. * The existing member at that position, and all others with higher indexes,
  38. * have their index increased by one.
  39. *
  40. * @param integer $index
  41. * @param object ResResource/ResLiteral $resResource
  42. * @return boolean
  43. * @access public
  44. */
  45. function addAtIndex($index, $object)
  46. {
  47. //get a members index
  48. $memberIndex= $this->getMembers();
  49. //renumber all higher members
  50. for ($i = count($memberIndex);$i >= $index ; $i--)
  51. {
  52. $this->removeAll($this->_getMembershipPropertyWithIndex($i));
  53. $this->addProperty($this->_getMembershipPropertyWithIndex($i+1),$memberIndex[$i]);
  54. }
  55. //remove the old value at this position
  56. $this->removeAll($this->_getMembershipPropertyWithIndex($index));
  57. //add the new value
  58. $this->addProperty($this->_getMembershipPropertyWithIndex($index),$object);
  59. return $this;
  60. }
  61. /**
  62. * Get the member at a given index
  63. *
  64. * @param integer $index
  65. * @return object ResResource/ResLiteral
  66. * @access public
  67. */
  68. function getMember($index)
  69. {
  70. $result=$this->listProperties($this->_getMembershipPropertyWithIndex($index));
  71. if (isset($result[0]))
  72. {
  73. return $result[0];
  74. }
  75. else
  76. {
  77. return null;
  78. }
  79. }
  80. /**
  81. * Return the index of a given member of the sequence.
  82. * If the same value appears more than once in the sequence, it is undefined
  83. * which of the indexes will be returned.
  84. * If the member is not found in this sequence, a value of 0 is returned.
  85. *
  86. * @param object ResResource/ResLiteral $object
  87. * @return integer
  88. * @access public
  89. */
  90. function indexOf($object)
  91. {
  92. //check all members, until $object is found
  93. foreach ($this->listProperties() as $statement)
  94. {
  95. $predicateLabel=$statement->getLabelPredicate();
  96. if ($this->_predicateLabelMatchesMembershipProperty($predicateLabel))
  97. {
  98. if($object->equals($statement->getObject()))
  99. //analyze the container membership property and return the index
  100. return $this->_getMemberIndexNrFromMembershipPropertyLabel($predicateLabel);
  101. }
  102. }
  103. //return 0 if $object wasn't found
  104. return 0;
  105. }
  106. /**
  107. * Remove the member at the specified index.
  108. * All other members with a higher index will have their index reduced by one.
  109. *
  110. * @param integer $index
  111. * @access public
  112. */
  113. function removeAtIndex($index)
  114. {
  115. $memberIndex= $this->getMembers();
  116.  
  117.  
  118. $this->removeAll($this->_getMembershipPropertyWithIndex($index));
  119.  
  120. for ($i = $index;$i < count($memberIndex); $i++)
  121. {
  122. $this->removeAll($this->_getMembershipPropertyWithIndex($i+1));
  123. $this->addProperty($this->_getMembershipPropertyWithIndex($i),$memberIndex[$i+1]);
  124. }
  125. return $this;
  126. }
  127. /**
  128. * Set the value at a given index in the sequence.
  129. *
  130. * If the index is not in the range of the sequence, false is returned
  131. *
  132. * @param integer $index
  133. * @return boolean
  134. * @access public
  135. */
  136. function set($index, $object)
  137. {
  138. if (!$this->hasProperty($this->_getMembershipPropertyWithIndex($index)))
  139. return false;
  140. $this->removeAll($this->_getMembershipPropertyWithIndex($index));
  141. $this->addProperty($this->_getMembershipPropertyWithIndex($index),$object);
  142. return true;
  143. }
  144. }
  145. ?>

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