| 1 | # $Id: V01.pm,v 1.28 2000/12/21 22:04:18 aigan Exp $ -*-perl-*- | ||
| 2 | |||
| 3 | package RDF::Service::Interface::Base::V01; | ||
| 4 | |||
| 5 | #===================================================================== | ||
| 6 | # | ||
| 7 | # DESCRIPTION | ||
| 8 | # Interface to the basic Resource actions | ||
| 9 | # | ||
| 10 | # AUTHOR | ||
| 11 | # Jonas Liljegren <jonas@paranormal.se> | ||
| 12 | # | ||
| 13 | # COPYRIGHT | ||
| 14 | # Copyright (C) 2000 Jonas Liljegren. All Rights Reserved. | ||
| 15 | # | ||
| 16 | # This module is free software; you can redistribute it and/or | ||
| 17 | # modify it under the same terms as Perl itself. | ||
| 18 | # | ||
| 19 | #===================================================================== | ||
| 20 | |||
| 21 | use strict; | ||
| 22 | use RDF::Service::Constants qw( :all ); | ||
| 23 | use RDF::Service::Cache qw( save_ids uri2id debug time_string | ||
| 24 | $DEBUG debug_start debug_end id2uri | ||
| 25 | validate_context ); | ||
| 26 | use URI; | ||
| 27 | use Data::Dumper; | ||
| 28 | use Carp qw( confess carp cluck croak ); | ||
| 29 | |||
| 30 | sub register | ||
| 31 | { | ||
| 32 | my( $interface ) = @_; | ||
| 33 | |||
| 34 | return | ||
| 35 | { | ||
| 36 | '' => | ||
| 37 | { | ||
| 38 | NS_LS.'#Service' => | ||
| 39 | { | ||
| 40 | 'connect' => [\&connect], | ||
| 41 | 'find_node' => [\&find_node], | ||
| 42 | }, | ||
| 43 | NS_LS.'#Model' => | ||
| 44 | { | ||
| 45 | 'create_model' => [\&create_model], | ||
| 46 | 'is_empty' => [\¬_implemented], | ||
| 47 | 'size' => [\¬_implemented], | ||
| 48 | 'validate' => [\¬_implemented], | ||
| 49 | |||
| 50 | # The NS. The base for added things... | ||
| 51 | 'source_uri'=> [\¬_implemented], | ||
| 52 | |||
| 53 | # is the model open or closed? | ||
| 54 | 'is_mutable'=> [\¬_implemented], | ||
| 55 | |||
| 56 | }, | ||
| 57 | NS_RDFS.'Literal' => | ||
| 58 | { | ||
| 59 | 'desig' => [\&desig_literal], | ||
| 60 | 'value' => [\&value], | ||
| 61 | }, | ||
| 62 | NS_RDF.'Statement' => | ||
| 63 | { | ||
| 64 | 'pred' => [\&pred], | ||
| 65 | 'subj' => [\&subj], | ||
| 66 | 'obj' => [\&obj], | ||
| 67 | 'desig' => [\&desig_statement], | ||
| 68 | }, | ||
| 69 | NS_RDFS.'Resource' => | ||
| 70 | { | ||
| 71 | 'desig' => [\&desig_resource], | ||
| 72 | 'delete_node_cascade' => [\&delete_node_cascade], | ||
| 73 | 'delete_node' => [\&delete_node], | ||
| 74 | 'init_types' => [\&noop], | ||
| 75 | 'init_rev_subjs' => [\&noop], | ||
| 76 | 'store_types' => [\&noop], | ||
| 77 | 'remove_types' => [\&noop], | ||
| 78 | 'store_node' => [\&noop], | ||
| 79 | 'store_props' => [\&noop], | ||
| 80 | }, | ||
| 81 | NS_RDFS.'Class' => | ||
| 82 | { | ||
| 83 | 'level' => [\&level], | ||
| 84 | 'init_rev_subjs' => [\&init_rev_subjs_class], | ||
| 85 | }, | ||
| 86 | }, | ||
| 87 | NS_LD."/service/" => | ||
| 88 | { | ||
| 89 | NS_RDFS.'Resource' => | ||
| 90 | { | ||
| 91 | 'init_types' => [\&init_types_service], | ||
| 92 | 'init_rev_subjs' => [\&init_rev_subjs], | ||
| 93 | }, | ||
| 94 | }, | ||
| 95 | &NS_LD."/literal/" => | ||
| 96 | { | ||
| 97 | NS_RDFS.'Resource' => | ||
| 98 | { | ||
| 99 | 'init_types' => [\&init_types_literal], | ||
| 100 | 'init_rev_subjs' => [\&init_rev_subjs], | ||
| 101 | }, | ||
| 102 | }, | ||
| 103 | &NS_LS => | ||
| 104 | { | ||
| 105 | NS_RDFS.'Resource' => | ||
| 106 | { | ||
| 107 | 'init_types' => [\&init_types], | ||
| 108 | 'init_rev_subjs' => [\&init_rev_subjs], | ||
| 109 | 'level' => [\&base_level], | ||
| 110 | }, | ||
| 111 | }, | ||
| 112 | &NS_RDF => | ||
| 113 | { | ||
| 114 | NS_RDFS.'Resource' => | ||
| 115 | { | ||
| 116 | 'init_types' => [\&init_types], | ||
| 117 | 'init_rev_subjs' => [\&init_rev_subjs], | ||
| 118 | 'level' => [\&base_level], | ||
| 119 | }, | ||
| 120 | }, | ||
| 121 | &NS_RDFS => | ||
| 122 | { | ||
| 123 | NS_RDFS.'Resource' => | ||
| 124 | { | ||
| 125 | 'init_types' => [\&init_types], | ||
| 126 | 'init_rev_subjs' => [\&init_rev_subjs], | ||
| 127 | 'level' => [\&base_level], | ||
| 128 | }, | ||
| 129 | }, | ||
| 130 | }; | ||
| 131 | } | ||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | # ??? Create literal URIs by apending '#val' to the statement URI | ||
| 136 | |||
| 137 | sub not_implemented { die "not implemented" } | ||
| 138 | |||
| 139 | # TODO: Remove this, but without fatal results | ||
| 140 | sub noop {0,0} # Do nothing and continue | ||
| 141 | |||
| 142 | sub connect | ||
| 143 | { | ||
| 144 | my( $self, $i, $module, $args ) = @_; | ||
| 145 | |||
| 146 | # Create the interface object. The IDS will be the same for the | ||
| 147 | # RDF object and the new interface object. Old interfaces doesn't | ||
| 148 | # get their IDS changed. | ||
| 149 | |||
| 150 | # A Interface is a source of statements. The interface also has | ||
| 151 | # special metadata, as the type of interface, its range, etc. The | ||
| 152 | # main property of the interface is its model that represents all | ||
| 153 | # the statements. The interface can also have a collection of | ||
| 154 | # literals, namespaces, resource names and other things. | ||
| 155 | |||
| 156 | |||
| 157 | # Create the new interface resource object | ||
| 158 | # | ||
| 159 | my $uri = _construct_interface_uri( $module, $args ); | ||
| 160 | my $node = $self->[NODE]; | ||
| 161 | |||
| 162 | |||
| 163 | |||
| 164 | if( $DEBUG >= 5 ) | ||
| 165 | { | ||
| 166 | debug "Nodes in this IDS:\n"; | ||
| 167 | foreach my $id ( keys %{$self->[WMODEL][NODE][REV_MODEL]} ) | ||
| 168 | { | ||
| 169 | my $obj = $self->get_context_by_id($id); | ||
| 170 | debug " $id: ".$obj->desig."\n"; | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | # Generate new IDS | ||
| 175 | # | ||
| 176 | my $new_ids = join('-', map(uri2id($_->[URISTR]), | ||
| 177 | @{$node->[INTERFACES]}), | ||
| 178 | uri2id($uri)); | ||
| 179 | |||
| 180 | # Initialize the cache for this IDS. Each IDS has it's own cache | ||
| 181 | # of node objects | ||
| 182 | # | ||
| 183 | $RDF::Service::Cache::node->{$new_ids} ||= {}; | ||
| 184 | |||
| 185 | # Update IDS and export model resources to new IDS | ||
| 186 | # | ||
| 187 | _export_to_ids( $self, $i, $node, $new_ids ); | ||
| 188 | |||
| 189 | |||
| 190 | |||
| 191 | # A new Service node should now have been created. Make $self | ||
| 192 | # point to the new node. Change the IDS in order to get it from | ||
| 193 | # the right IDS cache. Kill the old node! | ||
| 194 | # | ||
| 195 | my $new_node = $self->get_node_by_id( $node->[ID], $new_ids ); | ||
| 196 | $self->[NODE] = $new_node; | ||
| 197 | my $new_wmodel = | ||
| 198 | $self->get_context_by_id( $self->[WMODEL][NODE][ID], $new_ids ); | ||
| 199 | $self->[WMODEL] = $new_wmodel; | ||
| 200 | # debug "*!* New NODE has now IDS $self->[NODE][IDS]\n"; | ||
| 201 | # debug "*!* Setting new WMODEL to IDS $new_wmodel->[NODE][IDS]\n"; | ||
| 202 | $new_node->[INTERFACES] = $node->[INTERFACES]; | ||
| 203 | $node = undef; | ||
| 204 | |||
| 205 | |||
| 206 | |||
| 207 | # Create a new base model | ||
| 208 | # | ||
| 209 | my $base_model = $self->get_node(NS_LD.'#The_Base_Model', $new_ids); | ||
| 210 | $base_model->[TYPE_ALL] = 2; | ||
| 211 | debug "Changing SOLID to 1 for $base_model->[URISTR] ". | ||
| 212 | "IDS $base_model->[IDS]\n", 3; | ||
| 213 | $base_model->[SOLID] = 1; # nonchanging | ||
| 214 | $new_node->[MODEL] = $base_model; | ||
| 215 | |||
| 216 | # This should get the new *interface* node prepared by _export_to_ids | ||
| 217 | # | ||
| 218 | my $new_interface = $self->get( $uri, $new_ids ); | ||
| 219 | my $new_interface_node = $new_interface->[NODE]; | ||
| 220 | |||
| 221 | push @{$new_node->[INTERFACES]}, $new_interface_node; | ||
| 222 | save_ids( $new_ids, $new_node->[INTERFACES] ); | ||
| 223 | |||
| 224 | # Set up the new object, based on the IDS | ||
| 225 | # | ||
| 226 | $new_interface_node->[MODEL] = $self->[WMODEL][NODE]; # What is the model of this? | ||
| 227 | $new_interface_node->[MODULE_NAME] = $module; # This is not used | ||
| 228 | |||
| 229 | |||
| 230 | # OBS: The TYPE creation must wait. The type object depends on the | ||
| 231 | # RDFS interface object in the creation. So it can't be set until | ||
| 232 | # the RDFS interface has been created. The TYPE value will be set | ||
| 233 | # then needed. | ||
| 234 | |||
| 235 | # This is the functions offered by the interface. Pass on the | ||
| 236 | # interface initialization arguments. | ||
| 237 | # | ||
| 238 | my $file = $module; | ||
| 239 | $file =~ s!::!/!g; | ||
| 240 | $file .= ".pm"; | ||
| 241 | require "$file" or die $!; | ||
| 242 | |||
| 243 | |||
| 244 | debug "Registring $file\n", 1; | ||
| 245 | |||
| 246 | { no strict 'refs'; | ||
| 247 | $new_interface_node->[MODULE_REG] = | ||
| 248 | &{$module."::register"}( $new_interface_node, $args ); | ||
| 249 | } | ||
| 250 | |||
| 251 | return( $new_interface, 1 ); | ||
| 252 | } | ||
| 253 | |||
| 254 | |||
| 255 | |||
| 256 | sub create_model | ||
| 257 | { | ||
| 258 | my( $self, $i, $obj, $content ) = @_; | ||
| 259 | |||
| 260 | |||
| 261 | ### NOTES from old create_model in DBI | ||
| 262 | # | ||
| 263 | # We are asked to create a new resource and a new object | ||
| 264 | # representing that resource and a context for the resource | ||
| 265 | # object. The new resource must have an URI. The creator must | ||
| 266 | # own the $uri namespace, as statements will be placed in it.. | ||
| 267 | |||
| 268 | # If no URI is supplied, one will be generated by the method | ||
| 269 | # create_resource(). In case the URI is supplied, it will | ||
| 270 | # be validated by the appropriate interface. | ||
| 271 | |||
| 272 | |||
| 273 | |||
| 274 | # TODO: Validate the URI | ||
| 275 | |||
| 276 | $content ||= []; | ||
| 277 | |||
| 278 | unless( ref $obj ) | ||
| 279 | { | ||
| 280 | unless( defined $obj ) | ||
| 281 | { | ||
| 282 | $obj = NS_LD."/model/".&get_unique_id; | ||
| 283 | } | ||
| 284 | $obj = $self->get( $obj ); | ||
| 285 | } | ||
| 286 | |||
| 287 | my $obj_node = $obj->[NODE]; | ||
| 288 | |||
| 289 | debug " ( $obj_node->[URISTR] )\n", 2; | ||
| 290 | |||
| 291 | # The model consists of triples. The [content] holds the access | ||
| 292 | # points for the parts of the model. Each element can be either a | ||
| 293 | # triple, model, ns, prefix or interface. Each of ns, prefix and | ||
| 294 | # interface represents all the triples contained theirin. | ||
| 295 | |||
| 296 | # the second parameter is the interface of the created object | ||
| 297 | # That parameter will be removed and the interface list will be | ||
| 298 | # created from the availible interfaces as pointed to by the | ||
| 299 | # context signature. | ||
| 300 | |||
| 301 | |||
| 302 | $obj_node->[MODEL] = $self->[WMODEL][NODE]; | ||
| 303 | $self->[WMODEL][NODE][REV_MODEL]{$obj_node->[ID]} = $obj_node; | ||
| 304 | $obj_node->[FACT] = 1; # DEPRECATED | ||
| 305 | $obj_node->[NS] = $obj_node->[URISTR]; | ||
| 306 | $obj_node->[CONTENT] = $content; | ||
| 307 | $obj_node->[READONLY] = 0; | ||
| 308 | |||
| 309 | |||
| 310 | # The working model of the model will be the model itself. But | ||
| 311 | # the model of the model will be the working model of it's parent. | ||
| 312 | |||
| 313 | # What is the model of the model? Is it the parent model | ||
| 314 | # ($self->[MODEL]) or itself ($model) or some default | ||
| 315 | # (NS_LD."/model/system") or maby the interface? Answer: Its the | ||
| 316 | # parent model. Commonly the Service object. | ||
| 317 | # | ||
| 318 | $obj->[WMODEL] = $obj; | ||
| 319 | |||
| 320 | my $types = [ NS_LS.'#Model' ]; | ||
| 321 | my $props = | ||
| 322 | { | ||
| 323 | NS_LS.'#updated' => [time_string()], | ||
| 324 | }; | ||
| 325 | |||
| 326 | # Should the WMODEL not be $obj while we are setting the type of | ||
| 327 | # obj? | ||
| 328 | # | ||
| 329 | $obj->set( $types, $props ); | ||
| 330 | |||
| 331 | return $obj, 1; | ||
| 332 | } | ||
| 333 | |||
| 334 | |||
| 335 | |||
| 336 | sub init_types | ||
| 337 | { | ||
| 338 | my( $self, $i ) = @_; | ||
| 339 | |||
| 340 | # warn "***The model of $i is $i->[MODEL]\n"; | ||
| 341 | croak "Bad interface( $i )" unless ref $i eq "RDF::Service::Resource"; | ||
| 342 | |||
| 343 | my $success = 0; | ||
| 344 | |||
| 345 | if( my $entry = $Schema->{$self->[NODE][URISTR]}{NS_RDF.'type'} ) | ||
| 346 | { | ||
| 347 | $self->declare_add_types( &_obj_list($self, $i, $entry), | ||
| 348 | NS_LD.'#The_Base_Model', 1 ); | ||
| 349 | $success = 1; | ||
| 350 | } | ||
| 351 | if( my $entry = $Schema->{$self->[NODE][URISTR]}{NS_LS.'#name'} ) | ||
| 352 | { | ||
| 353 | $self->[NODE][NAME] = $entry; | ||
| 354 | } | ||
| 355 | |||
| 356 | return( $success, 3); | ||
| 357 | } | ||
| 358 | |||
| 359 | sub init_rev_subjs | ||
| 360 | { | ||
| 361 | my( $self, $i) = @_; | ||
| 362 | |||
| 363 | my $subj_uri = $self->[NODE][URISTR]; | ||
| 364 | my $subj = $self; | ||
| 365 | foreach my $pred_uri (keys %{$Schema->{$subj_uri}}) | ||
| 366 | { | ||
| 367 | # Make an exception for type | ||
| 368 | # | ||
| 369 | next if $pred_uri eq NS_RDF.'type'; | ||
| 370 | next if $pred_uri eq NS_LS.'#name'; | ||
| 371 | |||
| 372 | my $lref = $Schema->{$subj_uri}{$pred_uri}; | ||
| 373 | defined $lref or die "\$Schema->{$subj_uri}{$pred_uri} not defined\n"; | ||
| 374 | my $pred = $self->get($pred_uri); | ||
| 375 | |||
| 376 | # Just define the arcs. | ||
| 377 | # | ||
| 378 | _arcs_branch($self, $i, $subj, $pred, $lref); | ||
| 379 | } | ||
| 380 | |||
| 381 | return(1, 3); | ||
| 382 | } | ||
| 383 | |||
| 384 | |||
| 385 | sub init_rev_subjs_class | ||
| 386 | { | ||
| 387 | my( $self, $i ) = @_; | ||
| 388 | # | ||
| 389 | # A class inherits it's super-class subClassOf properties | ||
| 390 | |||
| 391 | debug "RDFS init_rev_subjs_class $self->[URISTR]\n", 1; | ||
| 392 | |||
| 393 | |||
| 394 | # Since init_rev_subjs_class() depends on that all the other | ||
| 395 | # init_rev_subjs has been called, it will call init_rev_subjs() | ||
| 396 | # from here. That would cause an infinite recurse unless the | ||
| 397 | # dispatcher would remember which interface subroutines it has | ||
| 398 | # called, by storing that in a hash in the context. The | ||
| 399 | # dispatcher will not call the same interface subroutine twice (in | ||
| 400 | # deapth) with the same arguments. | ||
| 401 | # | ||
| 402 | # TODO: But how do we know if the cyclic dependency was a mistake | ||
| 403 | # or not? In some cases, we should report it as an error. ... I | ||
| 404 | # will waite with this until we have the function/property | ||
| 405 | # equality. | ||
| 406 | # | ||
| 407 | # $self->init_rev_subjs; | ||
| 408 | |||
| 409 | |||
| 410 | my $subClassOf = $self->get(NS_RDFS.'subClassOf'); | ||
| 411 | |||
| 412 | # Could be optimized? | ||
| 413 | my $subj_uristr = $self->[NODE][URISTR]; | ||
| 414 | foreach my $pred_uristr ( keys %{$Schema->{$subj_uristr}} ) | ||
| 415 | { | ||
| 416 | my $lref = $Schema->{$subj_uristr}{$pred_uristr}; | ||
| 417 | defined $lref or | ||
| 418 | die "\$Schema->{$subj_uristr}{$pred_uristr} not defined\n"; | ||
| 419 | my $pred = $self->get($pred_uristr); | ||
| 420 | |||
| 421 | # This should recursively add all arcs | ||
| 422 | _arcs_branch($self, $i, $self, $pred, $lref); | ||
| 423 | |||
| 424 | if( $pred_uristr eq NS_RDFS.'subClassOf' ) | ||
| 425 | { | ||
| 426 | foreach my $superclass ( | ||
| 427 | @{ $self->arc_obj($subClassOf)->list } | ||
| 428 | ) | ||
| 429 | { | ||
| 430 | foreach my $multisuperclass ( | ||
| 431 | @{ $superclass->arc_obj($subClassOf)->list } | ||
| 432 | ) | ||
| 433 | { | ||
| 434 | |||
| 435 | # TODO: Place this dynamic statement in a special | ||
| 436 | # namespace | ||
| 437 | |||
| 438 | $self->declare_add_prop( $subClassOf, | ||
| 439 | $multisuperclass, undef, | ||
| 440 | undef, 1 ); | ||
| 441 | } | ||
| 442 | } | ||
| 443 | } | ||
| 444 | |||
| 445 | # TODO: Set create dependency on the subject and remove | ||
| 446 | # dependency on each added statement and change dependency on | ||
| 447 | # object literlas. | ||
| 448 | } | ||
| 449 | |||
| 450 | return( 1, 3 ); | ||
| 451 | } | ||
| 452 | |||
| 453 | |||
| 454 | sub base_level | ||
| 455 | { | ||
| 456 | my( $self, $point ) = @_; | ||
| 457 | |||
| 458 | my $level = $Schema->{$self->[NODE][URISTR]}{NS_LS.'#level'}; | ||
| 459 | defined $level or die "No level for $self->[NODE][URISTR]\n"; | ||
| 460 | return( $level, 1); | ||
| 461 | } | ||
| 462 | |||
| 463 | sub level | ||
| 464 | { | ||
| 465 | my( $self, $point ) = @_; | ||
| 466 | |||
| 467 | # The level of a node is a measure of it's place in the class | ||
| 468 | # heiarchy. The Resouce class is level 0. The level of a class | ||
| 469 | # is the level of the heighest superclass plus one. Used for | ||
| 470 | # sorting in type_orderd_list(). | ||
| 471 | |||
| 472 | # TODO: Store the level as a property | ||
| 473 | |||
| 474 | my $level = 0; | ||
| 475 | foreach my $sc ( @{$self->arc_obj(NS_RDFS.'subClassOf')->list} ) | ||
| 476 | { | ||
| 477 | my $sc_level = $sc->level; | ||
| 478 | $level = $sc_level if $sc_level > $level; | ||
| 479 | } | ||
| 480 | $level++; | ||
| 481 | |||
| 482 | return( $level, 1); | ||
| 483 | } | ||
| 484 | |||
| 485 | sub delete_node | ||
| 486 | { | ||
| 487 | my( $self ) = @_; | ||
| 488 | |||
| 489 | # Only deletes the part of the node associated with the WMODEL | ||
| 490 | |||
| 491 | if( $DEBUG ) | ||
| 492 | { | ||
| 493 | unless( ref $self eq 'RDF::Service::Context' ) | ||
| 494 | { | ||
| 495 | confess "Self $self not Context"; | ||
| 496 | } | ||
| 497 | } | ||
| 498 | |||
| 499 | my $node = $self->[NODE]; | ||
| 500 | my $wmodel = $self->[WMODEL]; | ||
| 501 | my $wmodel_id = $wmodel->[NODE][ID]; | ||
| 502 | |||
| 503 | |||
| 504 | die "Not implemented" if $node->[MULTI]; | ||
| 505 | |||
| 506 | $self->declare_del_types; | ||
| 507 | $self->declare_del_rev_types; | ||
| 508 | |||
| 509 | for(my $j=0; $j<= $#{$node->[REV_PRED]}; $j++) | ||
| 510 | { | ||
| 511 | # This model does not longer define the arc. Remove the | ||
| 512 | # property unless another model also defines the arc. (In | ||
| 513 | # which case delete_node returns false.) | ||
| 514 | |||
| 515 | my $arc_node = $node->[REV_PRED][$j]; | ||
| 516 | splice @{$node->[REV_PRED]}, $j--, 1 | ||
| 517 | if $self->new($arc_node)->delete_node; | ||
| 518 | } | ||
| 519 | |||
| 520 | foreach my $subj_id ( keys %{$node->[REV_SUBJ]} ) | ||
| 521 | { | ||
| 522 | for(my $j=0; $j<= $#{$node->[REV_SUBJ]{$subj_id}}; $j++ ) | ||
| 523 | { | ||
| 524 | # This model does not longer define the arc. Remove the | ||
| 525 | # property unless another model also defines the arc. | ||
| 526 | |||
| 527 | my $arc_node = $node->[REV_SUBJ]{$subj_id}[$j]; | ||
| 528 | splice @{$node->[REV_SUBJ]{$subj_id}}, $j--, 1 | ||
| 529 | if $self->new($arc_node)->delete_node; | ||
| 530 | } | ||
| 531 | delete $node->[REV_SUBJ]{$subj_id} | ||
| 532 | unless @{$node->[REV_SUBJ]{$subj_id}}; | ||
| 533 | } | ||
| 534 | |||
| 535 | foreach my $obj_id ( keys %{$node->[REV_OBJ]} ) | ||
| 536 | { | ||
| 537 | for(my $j=0; $j<= $#{$node->[REV_OBJ]{$obj_id}}; $j++ ) | ||
| 538 | { | ||
| 539 | # This model does not longer define the arc. Remove the | ||
| 540 | # property unless another model also defines the arc. | ||
| 541 | |||
| 542 | my $arc_node = $node->[REV_OBJ]{$obj_id}[$j]; | ||
| 543 | splice @{$node->[REV_OBJ]{$obj_id}}, $j--, 1 | ||
| 544 | if $self->new($arc_node)->delete_node; | ||
| 545 | } | ||
| 546 | delete $node->[REV_OBJ]{$obj_id} | ||
| 547 | unless @{$node->[REV_OBJ]{$obj_id}}; | ||
| 548 | } | ||
| 549 | |||
| 550 | # Should we delete the whole node? | ||
| 551 | # | ||
| 552 | if( $node->[MULTI] ) # Has another model defined this node? | ||
| 553 | { | ||
| 554 | # TODO: Something to do here? | ||
| 555 | debug "*** Did NOT remove $node->[URISTR]\n"; | ||
| 556 | debug "*** because of existing model\n"; | ||
| 557 | die "Not implemented"; | ||
| 558 | } | ||
| 559 | else | ||
| 560 | { | ||
| 561 | $self->remove; | ||
| 562 | |||
| 563 | # Is this a statement? | ||
| 564 | if( $node->[PRED] ) | ||
| 565 | { | ||
| 566 | # Expire all dependent lists | ||
| 567 | $node->[PRED][REV_PRED] = undef; | ||
| 568 | $node->[PRED][REV_PRED_ALL] = undef; | ||
| 569 | $node->[SUBJ][REV_SUBJ] = undef; | ||
| 570 | $node->[SUBJ][REV_SUBJ_ALL] = undef; | ||
| 571 | $node->[OBJ][REV_OBJ] = undef; | ||
| 572 | $node->[OBJ][REV_OBJ_ALL] = undef; | ||
| 573 | } | ||
| 574 | |||
| 575 | $node->[MODEL] = undef; | ||
| 576 | $self = undef; | ||
| 577 | } | ||
| 578 | return( 1, 1 ); | ||
| 579 | } | ||
| 580 | |||
| 581 | sub delete_node_cascade | ||
| 582 | { | ||
| 583 | my( $self, $i ) = @_; | ||
| 584 | # | ||
| 585 | # TODO: | ||
| 586 | # 1. The agent must be authenticated | ||
| 587 | # 2. Is the target model open? | ||
| 588 | # 3. Does the agent owns the target model? | ||
| 589 | # | ||
| 590 | # Special handling of implicit nodes | ||
| 591 | # | ||
| 592 | # Delete the node and all statements refering to the node. How | ||
| 593 | # will we handle dangling nodes, like the properties of the node | ||
| 594 | # mainly in the form of literals? We will not delete them if they | ||
| 595 | # belong to another model or if they are referenced in another | ||
| 596 | # statement (that itself is not among the statements to be | ||
| 597 | # deleted). But there could be references to the node from other | ||
| 598 | # interfaces that arn't even connected in this session. | ||
| 599 | # | ||
| 600 | # We could collect the dangling nodes and return them to the | ||
| 601 | # caller for decision. This could be made to an option. | ||
| 602 | |||
| 603 | # This version will delete from left to right. A deleted subject | ||
| 604 | # will delete all prperty statements and all objects. This will | ||
| 605 | # obviously have to change! | ||
| 606 | |||
| 607 | # Procedure: | ||
| 608 | # Foreach statement | ||
| 609 | # - call obj->delete | ||
| 610 | # Remove self | ||
| 611 | |||
| 612 | foreach my $arc ( @{ $self->arc->list} ) | ||
| 613 | { | ||
| 614 | my $obj = $arc->obj; | ||
| 615 | $obj->delete_node_cascade(); | ||
| 616 | } | ||
| 617 | |||
| 618 | return( $self->delete_node, 1 ); | ||
| 619 | } | ||
| 620 | |||
| 621 | |||
| 622 | sub find_node | ||
| 623 | { | ||
| 624 | my( $self, $i, $uri ) = @_; | ||
| 625 | |||
| 626 | my $obj = $RDF::Service::Cache::node->{$self->[NODE][IDS]}{ uri2id($uri) }; | ||
| 627 | return( RDF::Service::Context->new($obj, | ||
| 628 | $self->[CONTEXT], | ||
| 629 | $self->[WMODEL]), | ||
| 630 | 1) if $obj; | ||
| 631 | return( undef, 0 ); | ||
| 632 | } | ||
| 633 | |||
| 634 | sub init_types_service | ||
| 635 | { | ||
| 636 | my( $self, $i ) = @_; | ||
| 637 | # | ||
| 638 | # We currently doesn't store the service objects in any | ||
| 639 | # interface. The Base interface states that all URIs matching a | ||
| 640 | # specific pattern are Service objects. | ||
| 641 | |||
| 642 | debug "Initiating types for $self->[NODE][URISTR]\n", 1; | ||
| 643 | |||
| 644 | my $pattern = "^".NS_LD."/service/[^/#]+\$"; | ||
| 645 | if( $self->[NODE][URISTR] =~ m/$pattern/o ) | ||
| 646 | { | ||
| 647 | # Declare the types for the service | ||
| 648 | # | ||
| 649 | $self->declare_add_types([NS_LS.'#Service'], NS_LD.'#The_Base_Model', 1); | ||
| 650 | |||
| 651 | return( 0, 3 ); | ||
| 652 | } | ||
| 653 | |||
| 654 | return 0; | ||
| 655 | } | ||
| 656 | |||
| 657 | sub init_types_literal | ||
| 658 | { | ||
| 659 | my( $self, $i ) = @_; | ||
| 660 | |||
| 661 | debug "Initiating types for $self->[NODE][URISTR]\n", 1; | ||
| 662 | |||
| 663 | my $pattern = "^".NS_LD."/literal/[^/#]+\$"; | ||
| 664 | if( $self->[NODE][URISTR] =~ m/$pattern/o ) | ||
| 665 | { | ||
| 666 | # Declare the types for the literal | ||
| 667 | # | ||
| 668 | $self->declare_add_types([ | ||
| 669 | NS_RDFS.'Literal', | ||
| 670 | ], $self->get_node(NS_LD.'#The_Base_Model'), 1); | ||
| 671 | return( 0, 3 ); | ||
| 672 | } | ||
| 673 | return 0; | ||
| 674 | } | ||
| 675 | |||
| 676 | sub desig_literal | ||
| 677 | { | ||
| 678 | if( $_[0]->[NODE][VALUE] ) | ||
| 679 | { | ||
| 680 | return( "'${$_[0]->[NODE][VALUE]}'", 1); | ||
| 681 | } | ||
| 682 | else | ||
| 683 | { | ||
| 684 | return( "''", 1); | ||
| 685 | # return( desig($_[0]) ); | ||
| 686 | } | ||
| 687 | } | ||
| 688 | |||
| 689 | sub desig_statement | ||
| 690 | { | ||
| 691 | my( $self ) = @_; | ||
| 692 | |||
| 693 | my( $str ) = desig_resource($self); | ||
| 694 | |||
| 695 | my $pred = $self->pred->desig; | ||
| 696 | my $subj = $self->subj->desig; | ||
| 697 | my $obj = $self->obj->desig; | ||
| 698 | |||
| 699 | $str .= ": $pred of $subj is $obj\n"; | ||
| 700 | return( $str, 1); | ||
| 701 | } | ||
| 702 | |||
| 703 | sub desig_resource | ||
| 704 | { | ||
| 705 | # debug $_[0]->types_as_string, 1; | ||
| 706 | |||
| 707 | # Change to make method calls | ||
| 708 | # | ||
| 709 | my $str = ( $_[0]->[NODE][LABEL] || | ||
| 710 | $_[0]->[NODE][NAME] || | ||
| 711 | $_[0]->[NODE][URISTR] || | ||
| 712 | '(anonymous resource)' | ||
| 713 | ); | ||
| 714 | # debug "Desig of $_[0]->[NODE][URISTR] is $str\n", 1; | ||
| 715 | |||
| 716 | return( $str, 1 ); | ||
| 717 | } | ||
| 718 | |||
| 719 | |||
| 720 | |||
| 721 | |||
| 722 | # All methods with the prefix 'list_' will return a list of objects | ||
| 723 | # rather than a collection. (Model or collection of resources or | ||
| 724 | # literals.) But teh method will still return a ref to the list to | ||
| 725 | # the Dispatcher. | ||
| 726 | |||
| 727 | sub value | ||
| 728 | { | ||
| 729 | my( $self ) = @_; | ||
| 730 | $self->[NODE][REV_SUBJ_ALL] or $self->init_rev_subjs; | ||
| 731 | $self->[NODE][REV_SUBJ_ALL] ||= 1; | ||
| 732 | |||
| 733 | # warn "**** ".($self->types_as_string)."****\n"; | ||
| 734 | if( not defined $_[0]->[NODE][VALUE] ) | ||
| 735 | { | ||
| 736 | die "$self->[NODE][URISTR] has no defined value\n"; | ||
| 737 | } | ||
| 738 | |||
| 739 | # TODO: Should return 2 | ||
| 740 | return( ${$_[0]->[NODE][VALUE]}, 1); | ||
| 741 | } | ||
| 742 | |||
| 743 | |||
| 744 | sub pred | ||
| 745 | { | ||
| 746 | # TODO. Should return 2; | ||
| 747 | return( $_[0]->new($_[0]->[NODE][PRED]), 1); | ||
| 748 | } | ||
| 749 | |||
| 750 | sub subj | ||
| 751 | { | ||
| 752 | # TODO. Should return 2; | ||
| 753 | return( $_[0]->new($_[0]->[NODE][SUBJ]), 1); | ||
| 754 | } | ||
| 755 | |||
| 756 | sub obj | ||
| 757 | { | ||
| 758 | # TODO. Should return 2; | ||
| 759 | return( $_[0]->new($_[0]->[NODE][OBJ]), 1); | ||
| 760 | } | ||
| 761 | |||
| 762 | sub _export_to_ids | ||
| 763 | { | ||
| 764 | my( $self, $i, $node, $new_ids ) = @_; | ||
| 765 | |||
| 766 | debug_start( "_export_to_ids", ' ', $self ); | ||
| 767 | |||
| 768 | # warn "BBB1 Start by exporting $node->[URISTR]\n"; | ||
| 769 | |||
| 770 | _export_to_ids_node( $self, $i, $node, $new_ids ); | ||
| 771 | # warn "BBB2\n"; | ||
| 772 | |||
| 773 | foreach my $id ( keys %{$node->[REV_MODEL]} ) | ||
| 774 | { | ||
| 775 | # warn "BBB3\n"; | ||
| 776 | my $sub = $self->get_context_by_id($id); | ||
| 777 | if( $sub->is_known_as_a( NS_LS.'#Model' ) ) | ||
| 778 | { | ||
| 779 | # warn "BBB4\n"; | ||
| 780 | next if $sub->[NODE][ID] == $node->[ID]; | ||
| 781 | debug "Is a model ($sub->[NODE][URISTR]), ". | ||
| 782 | "checking it's content\n", 2; | ||
| 783 | _export_to_ids( $self, $i, $sub->[NODE], $new_ids ); | ||
| 784 | } | ||
| 785 | else | ||
| 786 | { | ||
| 787 | # warn "BBB5\n"; | ||
| 788 | next if $sub->[NODE][SOLID]; | ||
| 789 | _export_to_ids_node( $self, $i, $sub->[NODE], $new_ids ); | ||
| 790 | } | ||
| 791 | } | ||
| 792 | # warn "BBB6\n"; | ||
| 793 | |||
| 794 | # Transferens done. Empty list: | ||
| 795 | # | ||
| 796 | my $m = $self->[MEMORY]{$i->[ID]} ||= {}; | ||
| 797 | $m->{'transfered'} = undef; | ||
| 798 | |||
| 799 | debug_end( "_export_to_ids", ' ', $self ); | ||
| 800 | } | ||
| 801 | |||
| 802 | sub _export_to_ids_node | ||
| 803 | { | ||
| 804 | my( $self, $i, $subnode, $new_ids ) = @_; | ||
| 805 | |||
| 806 | unless( $i->[ID] ) | ||
| 807 | { | ||
| 808 | confess "Invalid interface ( $i )"; | ||
| 809 | } | ||
| 810 | |||
| 811 | # Remember which nodes we have transfered | ||
| 812 | # | ||
| 813 | my $m = $self->[MEMORY]{$i->[ID]} ||= {}; | ||
| 814 | return if $m->{'transfered'}{$subnode->[ID]}; | ||
| 815 | $m->{'transfered'}{$subnode->[ID]} ++; | ||
| 816 | |||
| 817 | |||
| 818 | |||
| 819 | debug_start("_export_to_ids_node", ' ', $self ); | ||
| 820 | debug " Exporting $subnode->[URISTR] $subnode->[ID] ". | ||
| 821 | "(IDS $subnode->[IDS])\n", 3; | ||
| 822 | |||
| 823 | if( $DEBUG ) | ||
| 824 | { | ||
| 825 | my $donelist = [sort keys %{$m->{'transfered'}}]; | ||
| 826 | debug "MEMORY @$donelist\n"; | ||
| 827 | } | ||
| 828 | |||
| 829 | |||
| 830 | my $cache = $RDF::Service::Cache::node->{$new_ids}; | ||
| 831 | |||
| 832 | my $new_node = $self->get_node_by_id($subnode->[ID], $new_ids); | ||
| 833 | |||
| 834 | # The $new_node has responsability now | ||
| 835 | # | ||
| 836 | debug "Changing SOLID to 1 for $subnode->[URISTR] ". | ||
| 837 | "IDS $subnode->[IDS]\n", 3; | ||
| 838 | $subnode->[SOLID] = 1; | ||
| 839 | |||
| 840 | my $model_id = $self->[WMODEL][NODE][ID]; | ||
| 841 | # warn "AAA1\n"; | ||
| 842 | |||
| 843 | $new_node->[IDS] = $new_ids; | ||
| 844 | $new_node->[NAME] = $subnode->[NAME]; | ||
| 845 | $new_node->[LABEL] = $subnode->[LABEL]; | ||
| 846 | $new_node->[MEMBER] = $subnode->[MEMBER]; | ||
| 847 | $new_node->[MULTI] = $subnode->[MULTI]; | ||
| 848 | $new_node->[VALUE] = $subnode->[VALUE]; | ||
| 849 | $new_node->[LANG] = $subnode->[LANG]; | ||
| 850 | |||
| 851 | # TODO: Transfer CONTENT (och READONLY) | ||
| 852 | # TODO: Transfer PREFIX, MODULE_NAME, MODULE_REG and INTERFACES | ||
| 853 | |||
| 854 | |||
| 855 | |||
| 856 | # Get the model from the new IDS | ||
| 857 | if( $subnode->[MODEL] ) | ||
| 858 | { | ||
| 859 | _export_to_ids_node( $self, $i, $subnode->[MODEL], $new_ids ); | ||
| 860 | my $subnode_model = | ||
| 861 | $self->get_node_by_id( $subnode->[MODEL][ID], $new_ids ); | ||
| 862 | debug "subnode_model $subnode_model->[URISTR] ". | ||
| 863 | "IDS $subnode_model->[IDS]\n", 3; | ||
| 864 | $new_node->[MODEL] = $subnode_model; | ||
| 865 | $new_node->[MODEL][REV_MODEL]{$new_node->[ID]} = $new_node; | ||
| 866 | } | ||
| 867 | |||
| 868 | # $new_node->[ALIASFOR] = $subnode->[ALIASFOR]; | ||
| 869 | |||
| 870 | my $new = RDF::Service::Context->new($new_node, | ||
| 871 | $self->[CONTEXT], | ||
| 872 | $self->[WMODEL]); | ||
| 873 | |||
| 874 | |||
| 875 | # warn "AAA2\n"; | ||
| 876 | |||
| 877 | foreach my $type_id ( keys %{$subnode->[TYPE]} ) | ||
| 878 | { | ||
| 879 | my $old_type_node = $self->get_node_by_id( $type_id ); | ||
| 880 | debug " TYPE $old_type_node->[URISTR] IDS $new_ids\n", 4; | ||
| 881 | debug " Checking...\n", 4; | ||
| 882 | |||
| 883 | next unless $subnode->[TYPE]{$type_id}; | ||
| 884 | if( $DEBUG >= 4 ) | ||
| 885 | { | ||
| 886 | next unless $subnode->[TYPE]{$type_id}{$model_id}; | ||
| 887 | debug " Solidity is ". | ||
| 888 | $subnode->[TYPE]{$type_id}{$model_id} ."\n", 2; | ||
| 889 | } | ||
| 890 | |||
| 891 | # Only transfer types belonging to the working model, that | ||
| 892 | # are marked as NONSOLID (==1) | ||
| 893 | # | ||
| 894 | unless( $subnode->[TYPE]{$type_id}{$model_id} and | ||
| 895 | $subnode->[TYPE]{$type_id}{$model_id} == 1 ) | ||
| 896 | { | ||
| 897 | next; | ||
| 898 | } | ||
| 899 | |||
| 900 | _export_to_ids_node( $self, $i, $old_type_node, $new_ids ); | ||
| 901 | my $type_node = $new->get_node_by_id( $type_id, $new_ids ); | ||
| 902 | |||
| 903 | debug " Transfering!\n", 4; | ||
| 904 | |||
| 905 | $subnode->[TYPE]{$type_id}{$model_id} = 2; | ||
| 906 | $new_node->[TYPE]{$type_id}{$model_id} = 1; | ||
| 907 | |||
| 908 | $type_node->[REV_TYPE]{$new_node->[ID]}{$model_id} = 1; | ||
| 909 | |||
| 910 | if( $DEBUG ) | ||
| 911 | { | ||
| 912 | my $model_uri = id2uri( $model_id ); | ||
| 913 | debug "Setting $type_node->[URISTR] ". | ||
| 914 | "(IDS $type_node->[IDS]) ". | ||
| 915 | "REV_TYPE $new_node->[URISTR] ". | ||
| 916 | "(IDS $new_node->[IDS]) ". | ||
| 917 | "in model $model_uri\n"; | ||
| 918 | } | ||
| 919 | } | ||
| 920 | |||
| 921 | # NB: REV_TYPE is ignored | ||
| 922 | |||
| 923 | # warn "AAA3\n"; | ||
| 924 | |||
| 925 | foreach my $arc_node ( @{$subnode->[REV_PRED]} ) | ||
| 926 | { | ||
| 927 | next unless $arc_node->[MODEL]; | ||
| 928 | next unless $arc_node->[MODEL][ID] == $model_id; | ||
| 929 | next if $arc_node->[SOLID]; | ||
| 930 | debug " REV_PRED $arc_node->[URISTR]\n", 2; | ||
| 931 | _export_to_ids_node( $self, $i, $arc_node, $new_ids ); | ||
| 932 | my $new_arc_node = | ||
| 933 | $self->get_node_by_id( $arc_node->[ID], $new_ids ); | ||
| 934 | push @{$new_node->[REV_PRED]}, $new_arc_node; | ||
| 935 | } | ||
| 936 | |||
| 937 | # warn "AAA4\n"; | ||
| 938 | |||
| 939 | foreach my $pred_id ( keys %{$subnode->[REV_SUBJ]} ) | ||
| 940 | { | ||
| 941 | $new_node->[REV_SUBJ]{$pred_id} = []; | ||
| 942 | foreach my $arc_node ( @{$subnode->[REV_SUBJ]{$pred_id}} ) | ||
| 943 | { | ||
| 944 | next unless $arc_node->[MODEL]; | ||
| 945 | next unless $arc_node->[MODEL][ID] == $model_id; | ||
| 946 | next if $arc_node->[SOLID]; | ||
| 947 | debug " REV_SUBJ $arc_node->[URISTR]\n", 2; | ||
| 948 | _export_to_ids_node( $self, $i, $arc_node, $new_ids ); | ||
| 949 | my $new_arc_node = | ||
| 950 | $self->get_node_by_id( $arc_node->[ID], $new_ids ); | ||
| 951 | push @{$new_node->[REV_SUBJ]{$pred_id}}, $new_arc_node; | ||
| 952 | } | ||
| 953 | delete $new_node->[REV_SUBJ]{$pred_id} unless | ||
| 954 | @{$new_node->[REV_SUBJ]{$pred_id}}; | ||
| 955 | } | ||
| 956 | |||
| 957 | # warn "AAA5\n"; | ||
| 958 | |||
| 959 | foreach my $pred_id ( keys %{$subnode->[REV_OBJ]} ) | ||
| 960 | { | ||
| 961 | $new_node->[REV_OBJ]{$pred_id} = []; | ||
| 962 | foreach my $arc_node ( @{$subnode->[REV_OBJ]{$pred_id}} ) | ||
| 963 | { | ||
| 964 | next unless $arc_node->[MODEL]; | ||
| 965 | next unless $arc_node->[MODEL][ID] == $model_id; | ||
| 966 | next if $arc_node->[SOLID]; | ||
| 967 | debug " REV_OBJ $arc_node->[URISTR]\n", 2; | ||
| 968 | _export_to_ids_node( $self, $i, $arc_node, $new_ids ); | ||
| 969 | my $new_arc_node = | ||
| 970 | $self->get_node_by_id( $arc_node->[ID], $new_ids ); | ||
| 971 | push @{$new_node->[REV_OBJ]{$pred_id}}, $new_arc_node; | ||
| 972 | } | ||
| 973 | delete $new_node->[REV_OBJ]{$pred_id} unless | ||
| 974 | @{$new_node->[REV_OBJ]{$pred_id}}; | ||
| 975 | } | ||
| 976 | |||
| 977 | # warn "AAA6\n"; | ||
| 978 | |||
| 979 | if( $subnode->[PRED] ) | ||
| 980 | { | ||
| 981 | debug " PRED/SUBJ/OBJ\n", 2; | ||
| 982 | |||
| 983 | |||
| 984 | _export_to_ids_node( $self, $i, $subnode->[PRED], $new_ids ); | ||
| 985 | my $new_pred_node = | ||
| 986 | $self->get_node_by_id($subnode->[PRED][ID], $new_ids); | ||
| 987 | push @{$new_pred_node->[REV_PRED]}, $new_node; | ||
| 988 | $new_node->[PRED] = $new_pred_node; | ||
| 989 | |||
| 990 | my $pred_id = $new_node->[PRED][ID]; | ||
| 991 | |||
| 992 | _export_to_ids_node( $self, $i, $subnode->[SUBJ], $new_ids ); | ||
| 993 | my $new_subj_node = | ||
| 994 | $self->get_node_by_id($subnode->[SUBJ][ID], $new_ids); | ||
| 995 | push @{$new_subj_node->[REV_SUBJ]{$pred_id}}, $new_node; | ||
| 996 | $new_node->[SUBJ] = $new_subj_node; | ||
| 997 | |||
| 998 | _export_to_ids_node( $self, $i, $subnode->[OBJ], $new_ids ); | ||
| 999 | my $new_obj_node = | ||
| 1000 | $self->get_node_by_id($subnode->[OBJ][ID], $new_ids); | ||
| 1001 | push @{$new_obj_node->[REV_OBJ]{$pred_id}}, $new_node; | ||
| 1002 | $new_node->[OBJ] = $new_obj_node; | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | |||
| 1006 | # warn "AAA7\n"; | ||
| 1007 | |||
| 1008 | $cache->{$new_node->[ID]} = $new_node; | ||
| 1009 | |||
| 1010 | debug_end( "_export_to_ids_node", ' ', $self ); | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | sub _construct_interface_uri | ||
| 1014 | { | ||
| 1015 | my( $module, $args ) = @_; | ||
| 1016 | |||
| 1017 | # Generate the URI of interface object. This will have to | ||
| 1018 | # change. The URI should be known or availible by request. Not | ||
| 1019 | # guessed. Make a clear distinction between the interface module | ||
| 1020 | # resource and the interface resource returned from a connection. | ||
| 1021 | # | ||
| 1022 | my $uri = URI->new("http://cpan.org/rdf/module/" | ||
| 1023 | . join('/',split /::/, $module)); | ||
| 1024 | |||
| 1025 | if( ref $args eq 'HASH' ) | ||
| 1026 | { | ||
| 1027 | my @query = (); | ||
| 1028 | foreach my $key ( sort keys %$args ) | ||
| 1029 | { | ||
| 1030 | next if $key eq 'passwd'; | ||
| 1031 | push @query, $key, $args->{$key}; | ||
| 1032 | } | ||
| 1033 | $uri->query_form(@query); | ||
| 1034 | } | ||
| 1035 | return $uri->as_string; | ||
| 1036 | } | ||
| 1037 | |||
| 1038 | |||
| 1039 | sub _obj_list | ||
| 1040 | { | ||
| 1041 | my( $self, $i, $ref ) = @_; | ||
| 1042 | my @objs = (); | ||
| 1043 | |||
| 1044 | if( ref $ref eq 'SCALAR' ) | ||
| 1045 | { | ||
| 1046 | push @objs, $self->get($$ref); | ||
| 1047 | } | ||
| 1048 | elsif( ref $ref eq 'ARRAY' ) | ||
| 1049 | { | ||
| 1050 | foreach my $obj ( @$ref ) | ||
| 1051 | { | ||
| 1052 | push @objs, _obj_list( $self, $i, $obj ); | ||
| 1053 | } | ||
| 1054 | } | ||
| 1055 | else | ||
| 1056 | { | ||
| 1057 | push @objs, $self->declare_literal($i, undef, $ref); | ||
| 1058 | } | ||
| 1059 | |||
| 1060 | return \@objs; | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | sub _arcs_branch | ||
| 1064 | { | ||
| 1065 | my( $self, $i, $subj, $pred, $lref ) = @_; | ||
| 1066 | |||
| 1067 | my $arcs = []; | ||
| 1068 | my $obj; | ||
| 1069 | if( ref $lref and ref $lref eq 'SCALAR' ) | ||
| 1070 | { | ||
| 1071 | my $obj_uri = $$lref; | ||
| 1072 | $obj = $self->get($obj_uri); | ||
| 1073 | } | ||
| 1074 | elsif( ref $lref and ref $lref eq 'HASH' ) | ||
| 1075 | { | ||
| 1076 | # Anonymous resource | ||
| 1077 | # (Sublevels is not returned) | ||
| 1078 | |||
| 1079 | die "Anonymous resources not supported"; | ||
| 1080 | # $obj = RDF::Service::Resource->new($ids, undef); | ||
| 1081 | } | ||
| 1082 | elsif( ref $lref and ref $lref eq 'ARRAY' ) | ||
| 1083 | { | ||
| 1084 | foreach my $item ( @$lref ) | ||
| 1085 | { | ||
| 1086 | _arcs_branch($self, $i, $subj, $pred, $item); | ||
| 1087 | } | ||
| 1088 | return 1; | ||
| 1089 | } | ||
| 1090 | else | ||
| 1091 | { | ||
| 1092 | confess("_arcs_branch called with undef obj: ".Dumper(\@_)) | ||
| 1093 | unless defined $lref; | ||
| 1094 | |||
| 1095 | # TODO: The model of the statement should be NS_RDFS or NS_RDF | ||
| 1096 | # or NS_LS, rather than $i | ||
| 1097 | # | ||
| 1098 | debug "_arcs_branch adds literal $lref\n", 1; | ||
| 1099 | $obj = $self->declare_literal( \$lref ); | ||
| 1100 | } | ||
| 1101 | |||
| 1102 | # TODO: Handle LABEL (and name) | ||
| 1103 | |||
| 1104 | unless( $pred->[NODE][URISTR] eq NS_RDF.'type' or | ||
| 1105 | $pred->[NODE][URISTR] eq NS_LS.'#name' ) | ||
| 1106 | { | ||
| 1107 | debug "_arcs_branch adds arc $pred->[NODE][URISTR]( ". | ||
| 1108 | "$subj->[NODE][URISTR], # $obj->[NODE][URISTR])\n", 3; | ||
| 1109 | $self->declare_arc( $pred, $subj, $obj, undef, | ||
| 1110 | undef, 1 ); | ||
| 1111 | } | ||
| 1112 | return 1; | ||
| 1113 | } | ||
| 1114 | |||
| 1115 | |||
| 1116 | 1; |