source: Dev/branches/rest-dojo-ui/jQueryUI/server/rdfapi/resModel/ResSeq.php @ 312

Last change on this file since 312 was 312, checked in by jkraaijeveld, 13 years ago
File size: 4.3 KB
Line 
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* @version  $Id: ResSeq.php 320 2006-11-21 09:38:51Z tgauss $
11* @author Daniel Westphal <mail at d-westphal dot de>
12*
13* @package      resModel
14* @access       public
15**/
16class ResSeq extends ResContainer
17{
18       
19        /**
20    * Constructor
21        * You can supply a URI
22    *
23    * @param string $uri
24        * @access       public
25    */         
26        function ResSeq($uri = null)
27        {
28                parent::ResContainer($uri);
29                $this->containerType=new ResResource(RDF_NAMESPACE_URI.RDF_SEQ);
30        }
31       
32        /**
33        * Insert a new member into the sequence at the specified position.
34        * The existing member at that position, and all others with higher indexes,
35        * have their index increased by one.
36        *
37        * @param        integer $index
38        * @param        object ResResource/ResLiteral   $resResource
39        * @return       boolean
40        * @access       public
41        */
42        function addAtIndex($index, $object)
43        {
44                //get a members index
45                $memberIndex= $this->getMembers();
46                               
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               
51                //renumber all higher members
52                for ($i = count($memberIndex);$i >= $index ; $i--)
53                {
54                        $this->removeAll($this->_getMembershipPropertyWithIndex($i));
55                        $this->addProperty($this->_getMembershipPropertyWithIndex($i+1),$memberIndex[$i]);
56                }       
57                //remove the old value at this position
58                $this->removeAll($this->_getMembershipPropertyWithIndex($index));
59                //add the new value
60                $this->addProperty($this->_getMembershipPropertyWithIndex($index),$object);
61                               
62                return $this;
63        }
64       
65        /**
66        * Get the member at a given index
67        *
68        * @param        integer $index
69        * @return       object ResResource/ResLiteral
70        * @access       public
71        */
72        function getMember($index)
73        {
74                $result=$this->listProperties($this->_getMembershipPropertyWithIndex($index));
75                if (isset($result[0]))
76                {
77                        return $result[0];
78                }
79                else
80                {
81                        return null;
82                }
83        }
84       
85        /**
86        * Return the index of a given member of the sequence.
87        * If the same value appears more than once in the sequence, it is undefined
88        * which of the indexes will be returned.
89        * If the member is not found in this sequence, a value of 0 is returned.
90        *
91        * @param        object ResResource/ResLiteral $object
92        * @return       integer
93        * @access       public
94        */
95        function indexOf($object)
96        {
97                //check all members, until $object is found
98                foreach ($this->listProperties() as $statement)
99                {
100                        $predicateLabel=$statement->getLabelPredicate();
101                        if ($this->_predicateLabelMatchesMembershipProperty($predicateLabel))
102                        {
103                                if($object->equals($statement->getObject()))
104                                        //analyze the container membership property and return the index
105                                        return $this->_getMemberIndexNrFromMembershipPropertyLabel($predicateLabel);
106                        }       
107                }
108                //return 0 if $object wasn't found
109                return 0;
110        }
111       
112        /**
113        * Remove the member at the specified index.
114        * All other members with a higher index will have their index reduced by one.
115        *
116        * @param        integer $index   
117        * @access       public
118        */
119        function removeAtIndex($index)
120        {
121                $memberIndex= $this->getMembers();
122
123
124                $this->removeAll($this->_getMembershipPropertyWithIndex($index));
125
126                for ($i = $index;$i < count($memberIndex); $i++)
127                {
128                        $this->removeAll($this->_getMembershipPropertyWithIndex($i+1));
129                        $this->addProperty($this->_getMembershipPropertyWithIndex($i),$memberIndex[$i+1]);
130                }               
131                return $this;
132        }
133       
134        /**
135        * Set the value at a given index in the sequence.
136        *
137        * If the index is not in the range of the sequence, false is returned
138        *
139        * @param        integer $index
140        * @return       boolean
141        * @access       public
142        */
143        function set($index, $object)
144        {
145                if (!$this->hasProperty($this->_getMembershipPropertyWithIndex($index)))
146                        return false;
147                       
148                $this->removeAll($this->_getMembershipPropertyWithIndex($index));
149                $this->addProperty($this->_getMembershipPropertyWithIndex($index),$object);
150                return true;
151        }
152}
153?>
Note: See TracBrowser for help on using the repository browser.