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. //type this container, if it isn't already typed
  50. if(!$this->hasProperty(new ResResource(RDF_NAMESPACE_URI.RDF_TYPE)))
  51. $this->addProperty(new ResResource(RDF_NAMESPACE_URI.RDF_TYPE),$this->containerType);
  52. //renumber all higher members
  53. for ($i = count($memberIndex);$i >= $index ; $i--)
  54. {
  55. $this->removeAll($this->_getMembershipPropertyWithIndex($i));
  56. $this->addProperty($this->_getMembershipPropertyWithIndex($i+1),$memberIndex[$i]);
  57. }
  58. //remove the old value at this position
  59. $this->removeAll($this->_getMembershipPropertyWithIndex($index));
  60. //add the new value
  61. $this->addProperty($this->_getMembershipPropertyWithIndex($index),$object);
  62. return $this;
  63. }
  64. /**
  65. * Get the member at a given index
  66. *
  67. * @param integer $index
  68. * @return object ResResource/ResLiteral
  69. * @access public
  70. */
  71. function getMember($index)
  72. {
  73. $result=$this->listProperties($this->_getMembershipPropertyWithIndex($index));
  74. if (isset($result[0]))
  75. {
  76. return $result[0];
  77. }
  78. else
  79. {
  80. return null;
  81. }
  82. }
  83. /**
  84. * Return the index of a given member of the sequence.
  85. * If the same value appears more than once in the sequence, it is undefined
  86. * which of the indexes will be returned.
  87. * If the member is not found in this sequence, a value of 0 is returned.
  88. *
  89. * @param object ResResource/ResLiteral $object
  90. * @return integer
  91. * @access public
  92. */
  93. function indexOf($object)
  94. {
  95. //check all members, until $object is found
  96. foreach ($this->listProperties() as $statement)
  97. {
  98. $predicateLabel=$statement->getLabelPredicate();
  99. if ($this->_predicateLabelMatchesMembershipProperty($predicateLabel))
  100. {
  101. if($object->equals($statement->getObject()))
  102. //analyze the container membership property and return the index
  103. return $this->_getMemberIndexNrFromMembershipPropertyLabel($predicateLabel);
  104. }
  105. }
  106. //return 0 if $object wasn't found
  107. return 0;
  108. }
  109. /**
  110. * Remove the member at the specified index.
  111. * All other members with a higher index will have their index reduced by one.
  112. *
  113. * @param integer $index
  114. * @access public
  115. */
  116. function removeAtIndex($index)
  117. {
  118. $memberIndex= $this->getMembers();
  119.  
  120.  
  121. $this->removeAll($this->_getMembershipPropertyWithIndex($index));
  122.  
  123. for ($i = $index;$i < count($memberIndex); $i++)
  124. {
  125. $this->removeAll($this->_getMembershipPropertyWithIndex($i+1));
  126. $this->addProperty($this->_getMembershipPropertyWithIndex($i),$memberIndex[$i+1]);
  127. }
  128. return $this;
  129. }
  130. /**
  131. * Set the value at a given index in the sequence.
  132. *
  133. * If the index is not in the range of the sequence, false is returned
  134. *
  135. * @param integer $index
  136. * @return boolean
  137. * @access public
  138. */
  139. function set($index, $object)
  140. {
  141. if (!$this->hasProperty($this->_getMembershipPropertyWithIndex($index)))
  142. return false;
  143. $this->removeAll($this->_getMembershipPropertyWithIndex($index));
  144. $this->addProperty($this->_getMembershipPropertyWithIndex($index),$object);
  145. return true;
  146. }
  147. }
  148. ?>

Documentation generated on Thu, 7 Jul 2005 13:43:52 +0200 by phpDocumentor 1.3.0RC3