deprecated/buildtools/buildsystemtools/lib/XML/DOM/NamedNodeMap.pm
author lorewang
Thu, 11 Nov 2010 11:26:32 +0800
changeset 677 44e49837144a
parent 655 3f65fd25dfd4
permissions -rw-r--r--
update release info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
655
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     1
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     2
package XML::DOM::NamedNodeMap;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     3
######################################################################
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     4
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     5
use strict;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     6
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     7
use Carp;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     8
use XML::DOM::DOMException;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
     9
use XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    10
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    11
use vars qw( $Special );
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    12
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    13
# Constant definition:
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    14
# Note: a real Name should have at least 1 char, so nobody else should use this
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    15
$Special = "";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    16
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    17
sub new 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    18
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    19
    my ($class, %args) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    20
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    21
    $args{Values} = new XML::DOM::NodeList;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    22
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    23
    # Store all NamedNodeMap properties in element $Special
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    24
    bless { $Special => \%args}, $class;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    25
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    26
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    27
sub getNamedItem 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    28
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    29
    # Don't return the $Special item!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    30
    ($_[1] eq $Special) ? undef : $_[0]->{$_[1]};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    31
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    32
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    33
sub setNamedItem 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    34
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    35
    my ($self, $node) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    36
    my $prop = $self->{$Special};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    37
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    38
    my $name = $node->getNodeName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    39
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    40
    if ($XML::DOM::SafeMode)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    41
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    42
	croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    43
	    if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    44
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    45
	croak new XML::DOM::DOMException (WRONG_DOCUMENT_ERR)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    46
	    if $node->[XML::DOM::Node::_Doc] != $prop->{Doc};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    47
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    48
	croak new XML::DOM::DOMException (INUSE_ATTRIBUTE_ERR)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    49
	    if defined ($node->[XML::DOM::Node::_UsedIn]);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    50
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    51
	croak new XML::DOM::DOMException (INVALID_CHARACTER_ERR,
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    52
		      "can't add name with NodeName [$name] to NamedNodeMap")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    53
	    if $name eq $Special;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    54
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    55
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    56
    my $values = $prop->{Values};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    57
    my $index = -1;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    58
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    59
    my $prev = $self->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    60
    if (defined $prev)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    61
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    62
	# decouple previous node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    63
	$prev->decoupleUsedIn;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    64
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    65
	# find index of $prev
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    66
	$index = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    67
	for my $val (@{$values})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    68
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    69
	    last if ($val == $prev);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    70
	    $index++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    71
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    72
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    73
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    74
    $self->{$name} = $node;    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    75
    $node->[XML::DOM::Node::_UsedIn] = $self;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    76
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    77
    if ($index == -1)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    78
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    79
	push (@{$values}, $node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    80
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    81
    else	# replace previous node with new node
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    82
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    83
	splice (@{$values}, $index, 1, $node);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    84
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    85
    
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    86
    $prev;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    87
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    88
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    89
sub removeNamedItem 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    90
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    91
    my ($self, $name) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    92
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    93
    # Be careful that user doesn't delete $Special node!
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    94
    croak new XML::DOM::DOMException (NOT_FOUND_ERR)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    95
        if $name eq $Special;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    96
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    97
    my $node = $self->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    98
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
    99
    croak new XML::DOM::DOMException (NOT_FOUND_ERR)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   100
        unless defined $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   101
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   102
    # The DOM Spec doesn't mention this Exception - I think it's an oversight
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   103
    croak new XML::DOM::DOMException (NO_MODIFICATION_ALLOWED_ERR)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   104
	if $self->isReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   105
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   106
    $node->decoupleUsedIn;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   107
    delete $self->{$name};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   108
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   109
    # remove node from Values list
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   110
    my $values = $self->getValues;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   111
    my $index = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   112
    for my $val (@{$values})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   113
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   114
	if ($val == $node)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   115
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   116
	    splice (@{$values}, $index, 1, ());
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   117
	    last;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   118
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   119
	$index++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   120
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   121
    $node;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   122
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   123
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   124
# The following 2 are really bogus. DOM should use an iterator instead (Clark)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   125
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   126
sub item 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   127
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   128
    my ($self, $item) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   129
    $self->{$Special}->{Values}->[$item];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   130
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   131
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   132
sub getLength 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   133
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   134
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   135
    my $vals = $self->{$Special}->{Values};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   136
    int (@$vals);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   137
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   138
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   139
#------------------------------------------------------------
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   140
# Extra method implementations
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   141
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   142
sub isReadOnly
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   143
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   144
    return 0 if $XML::DOM::IgnoreReadOnly;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   145
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   146
    my $used = $_[0]->{$Special}->{UsedIn};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   147
    defined $used ? $used->isReadOnly : 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   148
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   149
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   150
sub cloneNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   151
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   152
    my ($self, $deep) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   153
    my $prop = $self->{$Special};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   154
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   155
    my $map = new XML::DOM::NamedNodeMap (Doc => $prop->{Doc});
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   156
    # Not copying Parent property on purpose! 
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   157
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   158
    local $XML::DOM::IgnoreReadOnly = 1;	# temporarily...
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   159
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   160
    for my $val (@{$prop->{Values}})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   161
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   162
	my $key = $val->getNodeName;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   163
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   164
	my $newNode = $val->cloneNode ($deep);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   165
	$newNode->[XML::DOM::Node::_UsedIn] = $map;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   166
	$map->{$key} = $newNode;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   167
	push (@{$map->{$Special}->{Values}}, $newNode);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   168
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   169
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   170
    $map;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   171
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   172
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   173
sub setOwnerDocument
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   174
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   175
    my ($self, $doc) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   176
    my $special = $self->{$Special};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   177
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   178
    $special->{Doc} = $doc;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   179
    for my $kid (@{$special->{Values}})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   180
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   181
	$kid->setOwnerDocument ($doc);
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   182
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   183
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   184
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   185
sub getChildIndex
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   186
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   187
    my ($self, $attr) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   188
    my $i = 0;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   189
    for my $kid (@{$self->{$Special}->{Values}})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   190
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   191
	return $i if $kid == $attr;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   192
	$i++;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   193
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   194
    -1;	# not found
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   195
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   196
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   197
sub getValues
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   198
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   199
    wantarray ? @{ $_[0]->{$Special}->{Values} } : $_[0]->{$Special}->{Values};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   200
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   201
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   202
# Remove circular dependencies. The NamedNodeMap and its values should
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   203
# not be used afterwards.
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   204
sub dispose
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   205
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   206
    my $self = shift;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   207
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   208
    for my $kid (@{$self->getValues})
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   209
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   210
	undef $kid->[XML::DOM::Node::_UsedIn]; # was delete
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   211
	$kid->dispose;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   212
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   213
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   214
    delete $self->{$Special}->{Doc};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   215
    delete $self->{$Special}->{Parent};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   216
    delete $self->{$Special}->{Values};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   217
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   218
    for my $key (keys %$self)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   219
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   220
	delete $self->{$key};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   221
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   222
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   223
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   224
sub setParentNode
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   225
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   226
    $_[0]->{$Special}->{Parent} = $_[1];
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   227
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   228
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   229
sub getProperty
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   230
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   231
    $_[0]->{$Special}->{$_[1]};
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   232
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   233
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   234
#?? remove after debugging
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   235
sub toString
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   236
{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   237
    my ($self) = @_;
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   238
    my $str = "NamedNodeMap[";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   239
    while (my ($key, $val) = each %$self)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   240
    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   241
	if ($key eq $Special)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   242
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   243
	    $str .= "##Special (";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   244
	    while (my ($k, $v) = each %$val)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   245
	    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   246
		if ($k eq "Values")
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   247
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   248
		    $str .= $k . " => [";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   249
		    for my $a (@$v)
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   250
		    {
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   251
#			$str .= $a->getNodeName . "=" . $a . ",";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   252
			$str .= $a->toString . ",";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   253
		    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   254
		    $str .= "], ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   255
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   256
		else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   257
		{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   258
		    $str .= $k . " => " . $v . ", ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   259
		}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   260
	    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   261
	    $str .= "), ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   262
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   263
	else
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   264
	{
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   265
	    $str .= $key . " => " . $val . ", ";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   266
	}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   267
    }
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   268
    $str . "]";
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   269
}
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   270
3f65fd25dfd4 sync up SVN codes
kelvzhu
parents:
diff changeset
   271
1; # package return code