Source for file ResSeq.php

Documentation is available at ResSeq.php

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

Documentation generated on Fri, 13 Jan 2006 07:49:33 +0100 by phpDocumentor 1.3.0RC4