1 |
package Message::DOM::AttributeDefinition; |
2 |
use strict; |
3 |
our $VERSION=do{my @r=(q$Revision: 1.12 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
push our @ISA, 'Message::DOM::Node', 'Message::IF::AttributeDefinition'; |
5 |
require Message::DOM::Node; |
6 |
require Message::DOM::Attr; |
7 |
|
8 |
sub ____new ($$$) { |
9 |
my $self = shift->SUPER::____new (shift); |
10 |
$$self->{node_name} = $_[0]; |
11 |
$$self->{child_nodes} = []; |
12 |
$$self->{allowed_tokens} = []; |
13 |
return $self; |
14 |
} # ____new |
15 |
|
16 |
sub AUTOLOAD { |
17 |
my $method_name = our $AUTOLOAD; |
18 |
$method_name =~ s/.*:://; |
19 |
return if $method_name eq 'DESTROY'; |
20 |
|
21 |
if ({ |
22 |
## Read-only attributes (trivial accessors) |
23 |
node_name => 1, |
24 |
owner_element_type_definition => 1, |
25 |
}->{$method_name}) { |
26 |
no strict 'refs'; |
27 |
eval qq{ |
28 |
sub $method_name (\$) { |
29 |
return \${\$_[0]}->{$method_name}; |
30 |
} |
31 |
}; |
32 |
goto &{ $AUTOLOAD }; |
33 |
} else { |
34 |
require Carp; |
35 |
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
36 |
} |
37 |
} # AUTOLOAD |
38 |
|
39 |
## |AttributeDefinition| constants |
40 |
|
41 |
## |DeclaredValueType| |
42 |
sub NO_TYPE_ATTR () { 0 } |
43 |
sub CDATA_ATTR () { 1 } |
44 |
sub ID_ATTR () { 2 } |
45 |
sub IDREF_ATTR () { 3 } |
46 |
sub IDREFS_ATTR () { 4 } |
47 |
sub ENTITY_ATTR () { 5 } |
48 |
sub ENTITIES_ATTR () { 6 } |
49 |
sub NMTOKEN_ATTR () { 7 } |
50 |
sub NMTOKENS_ATTR () { 8 } |
51 |
sub NOTATION_ATTR () { 9 } |
52 |
sub ENUMERATION_ATTR () { 10 } |
53 |
sub UNKNOWN_ATTR () { 11 } |
54 |
|
55 |
## |DefaultValueType| |
56 |
sub UNKNOWN_DEFAULT () { 0 } |
57 |
sub FIXED_DEFAULT () { 1 } |
58 |
sub REQUIRED_DEFAULT () { 2 } |
59 |
sub IMPLIED_DEFAULT () { 3 } |
60 |
sub EXPLICIT_DEFAULT () { 4 } |
61 |
|
62 |
## |Node| attributes |
63 |
|
64 |
sub node_name ($); |
65 |
|
66 |
sub node_type () { 81002 } # ATTRIBUTE_DEFINITION_NODE |
67 |
|
68 |
*node_value = \&Message::DOM::Node::text_content; |
69 |
|
70 |
## |Node| methods |
71 |
|
72 |
*append_child = \&Message::DOM::Attr::append_child; |
73 |
|
74 |
*insert_before = \&Message::DOM::Attr::insert_before; |
75 |
|
76 |
*replace_child = \&Message::DOM::Attr::replace_child; |
77 |
|
78 |
## |AttributeDefinition| attributes |
79 |
|
80 |
sub allowed_tokens ($) { |
81 |
require Message::DOM::DOMStringList; |
82 |
return bless \[$_[0], 'allowed_tokens'], 'Message::DOM::DOMStringList'; |
83 |
} # allowed_tokens |
84 |
|
85 |
sub declared_type ($;$) { |
86 |
my $self = $_[0]; |
87 |
if (@_ > 1) { |
88 |
if (${$$self->{owner_document}}->{strict_error_checking}) { |
89 |
if ($$self->{manakai_read_only}) { |
90 |
report Message::DOM::DOMException |
91 |
-object => $self, |
92 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
93 |
-subtype => 'READ_ONLY_NODE_ERR'; |
94 |
} |
95 |
} |
96 |
if ($_[1]) { |
97 |
$$self->{declared_type} = 0+$_[1]; |
98 |
} else { |
99 |
delete $$self->{declared_type}; |
100 |
} |
101 |
} |
102 |
|
103 |
return $$self->{declared_type} || 0; |
104 |
} # declared_type |
105 |
|
106 |
sub default_type ($;$) { |
107 |
my $self = $_[0]; |
108 |
if (@_ > 1) { |
109 |
if (${$$self->{owner_document}}->{strict_error_checking}) { |
110 |
if ($$self->{manakai_read_only}) { |
111 |
report Message::DOM::DOMException |
112 |
-object => $self, |
113 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
114 |
-subtype => 'READ_ONLY_NODE_ERR'; |
115 |
} |
116 |
} |
117 |
if ($_[1]) { |
118 |
$$self->{default_type} = 0+$_[1]; |
119 |
} else { |
120 |
delete $$self->{default_type}; |
121 |
} |
122 |
} |
123 |
|
124 |
return $$self->{default_type} || 0; |
125 |
} # default_type |
126 |
|
127 |
sub owner_element_type_definition ($); |
128 |
|
129 |
package Message::IF::AttributeDefinition; |
130 |
|
131 |
package Message::DOM::Document; |
132 |
|
133 |
sub create_attribute_definition ($$) { |
134 |
if (${$_[0]}->{strict_error_checking}) { |
135 |
my $xv = $_[0]->xml_version; |
136 |
if (defined $xv) { |
137 |
if ($xv eq '1.0' and |
138 |
$_[1] =~ /\A\p{InXML_NameStartChar10}\p{InXMLNameChar10}*\z/) { |
139 |
# |
140 |
} elsif ($xv eq '1.1' and |
141 |
$_[1] =~ /\A\p{InXMLNameStartChar11}\p{InXMLNameChar11}*\z/) { |
142 |
# |
143 |
} else { |
144 |
report Message::DOM::DOMException |
145 |
-object => $_[0], |
146 |
-type => 'INVALID_CHARACTER_ERR', |
147 |
-subtype => 'MALFORMED_NAME_ERR'; |
148 |
} |
149 |
} |
150 |
} |
151 |
|
152 |
return Message::DOM::AttributeDefinition->____new (@_[0, 1]); |
153 |
} # create_attribute_definition |
154 |
|
155 |
=head1 LICENSE |
156 |
|
157 |
Copyright 2007 Wakaba <w@suika.fam.cx> |
158 |
|
159 |
This program is free software; you can redistribute it and/or |
160 |
modify it under the same terms as Perl itself. |
161 |
|
162 |
=cut |
163 |
|
164 |
1; |
165 |
## $Date: 2007/07/14 16:32:27 $ |