| 1 | # $Id: Resource.pm,v 1.22 2000/12/21 20:07:48 aigan Exp $ -*-perl-*- | ||
| 2 | |||
| 3 | package RDF::Service::Resource; | ||
| 4 | |||
| 5 | #===================================================================== | ||
| 6 | # | ||
| 7 | # DESCRIPTION | ||
| 8 | # The main Resource class. Implement actions accessable by all | ||
| 9 | # resources | ||
| 10 | # | ||
| 11 | # AUTHOR | ||
| 12 | # Jonas Liljegren <jonas@paranormal.se> | ||
| 13 | # | ||
| 14 | # COPYRIGHT | ||
| 15 | # Copyright (C) 2000 Jonas Liljegren. All Rights Reserved. | ||
| 16 | # | ||
| 17 | # This module is free software; you can redistribute it and/or | ||
| 18 | # modify it under the same terms as Perl itself. | ||
| 19 | # | ||
| 20 | #===================================================================== | ||
| 21 | |||
| 22 | use strict; | ||
| 23 | use RDF::Service::Dispatcher; | ||
| 24 | use RDF::Service::Constants qw( :all ); | ||
| 25 | use RDF::Service::Cache qw( interfaces uri2id list_prefixes | ||
| 26 | get_unique_id id2uri debug $DEBUG ); #); | ||
| 27 | use Data::Dumper; | ||
| 28 | use Carp qw( cluck confess croak carp ); | ||
| 29 | |||
| 30 | |||
| 31 | sub new_by_id | ||
| 32 | { | ||
| 33 | return new($_[0], undef, $_[1]); | ||
| 34 | } | ||
| 35 | |||
| 36 | sub new_with_ids | ||
| 37 | { | ||
| 38 | return new($_[0], undef, undef, $_[1]); | ||
| 39 | } | ||
| 40 | |||
| 41 | sub new | ||
| 42 | { | ||
| 43 | my( $proto, $uri, $id, $ids ) = @_; | ||
| 44 | |||
| 45 | # This constructor shouls only be called from get_node, which | ||
| 46 | # could be called from find_node or create_node. get_node will | ||
| 47 | # first look in the cache for this resource. | ||
| 48 | |||
| 49 | my $class = ref($proto) || $proto; | ||
| 50 | my $self = bless [], $class; | ||
| 51 | |||
| 52 | |||
| 53 | |||
| 54 | $self->[IDS] = ''; # This should only be used in the bootstrap | ||
| 55 | # TODO: Use bootstrap mode for allow this | ||
| 56 | |||
| 57 | if( ref($proto) ) | ||
| 58 | { | ||
| 59 | if( $DEBUG ) | ||
| 60 | { | ||
| 61 | if( ref $proto ne 'RDF::Service::Resource') | ||
| 62 | { | ||
| 63 | confess "The proto $proto is of wrong type"; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | $self->[IDS] = $proto->[IDS]; | ||
| 68 | } | ||
| 69 | |||
| 70 | if( $ids ) | ||
| 71 | { | ||
| 72 | $self->[IDS] = $ids; | ||
| 73 | } | ||
| 74 | |||
| 75 | if( $uri ) | ||
| 76 | { | ||
| 77 | $self->[URISTR] = $uri or die "No URI for $self"; | ||
| 78 | $self->[ID] = uri2id( $self->[URISTR] ); | ||
| 79 | } | ||
| 80 | elsif( $id ) | ||
| 81 | { | ||
| 82 | $self->[URISTR] = id2uri($id); | ||
| 83 | $self->[ID] = $id; | ||
| 84 | } | ||
| 85 | else | ||
| 86 | { | ||
| 87 | $self->[ID] = $proto->[ID]; | ||
| 88 | $self->[URISTR] = $proto->[URISTR]; | ||
| 89 | } | ||
| 90 | |||
| 91 | $self->[TYPE] = {}; | ||
| 92 | $self->[TYPE_ALL] = undef; | ||
| 93 | $self->[REV_TYPE] = {}; | ||
| 94 | $self->[REV_TYPE_ALL] = undef; | ||
| 95 | $self->[REV_PRED] = []; | ||
| 96 | $self->[REV_PRED_ALL] = undef; | ||
| 97 | $self->[REV_SUBJ] = {}; | ||
| 98 | $self->[REV_SUBJ_ALL] = undef; | ||
| 99 | $self->[REV_OBJ] = {}; | ||
| 100 | $self->[REV_OBJ_ALL] = undef; | ||
| 101 | |||
| 102 | debug "Changing SOLID to 0 for $self->[URISTR] ". | ||
| 103 | "IDS $self->[IDS]\n", 3; | ||
| 104 | $self->[SOLID] = 0; | ||
| 105 | |||
| 106 | $self->[JUMPTABLE] = undef; | ||
| 107 | |||
| 108 | $self->[NS] = undef; | ||
| 109 | $self->[NAME] = undef; | ||
| 110 | $self->[LABEL] = undef; | ||
| 111 | |||
| 112 | $self->[PRIVATE] = {}; | ||
| 113 | $self->[MODEL] = undef; | ||
| 114 | |||
| 115 | $self->[ALIASFOR] = undef; | ||
| 116 | |||
| 117 | $self->[JTK] = "--no value--"; | ||
| 118 | |||
| 119 | $self->[RUNLEVEL] = 1; | ||
| 120 | |||
| 121 | return $self; | ||
| 122 | } | ||
| 123 | |||
| 124 | |||
| 125 | |||
| 126 | sub find_prefix_id | ||
| 127 | { | ||
| 128 | my( $self ) = @_; | ||
| 129 | # | ||
| 130 | # Return the longest prefix in the interface jumptables matching | ||
| 131 | # the URI. | ||
| 132 | |||
| 133 | # cluck " *** find_prefix_id *** \n"; | ||
| 134 | |||
| 135 | debug "Finding prefix_id for $self->[URISTR]\n", 2; | ||
| 136 | foreach my $prefix ( &list_prefixes($self->[IDS]) ) | ||
| 137 | { | ||
| 138 | debug "..Checking $prefix\n", 2; | ||
| 139 | if( $self->[URISTR] =~ /^\Q$prefix/ ) | ||
| 140 | { | ||
| 141 | debug "....Done!\n", 2; | ||
| 142 | return uri2id($prefix); | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | die "Prefixlist failed to return at least ''\n"; | ||
| 147 | } | ||
| 148 | |||
| 149 | |||
| 150 | 1; | ||
| 151 | |||
| 152 | |||
| 153 | __END__ |