source: Dev/branches/jQueryUI/server/rdfapi/resModel/ResResource.php @ 249

Last change on this file since 249 was 249, checked in by hendrikvanantwerpen, 13 years ago

This one's for Subversion, because it's so close...

First widget (stripped down sequencer).
Seperated client and server code in two direcotry trees.

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