|
1 # |
|
2 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 # This package contains routines to read the information from the Feature registry XML file. |
|
18 package featureregistry; # Derived class implementation for feature registry xml file |
|
19 |
|
20 BEGIN { |
|
21 @ISA = qw(featureparser); # Derived from featureparser |
|
22 require featureparser; |
|
23 }; |
|
24 |
|
25 # Parse the featureregistry XML file and generate the maps and counts |
|
26 # |
|
27 #feature hash map: |
|
28 # {<uid1>}{name}<name> |
|
29 # {installable}<true\false> - optional |
|
30 # |
|
31 |
|
32 # |
|
33 # Class constructor |
|
34 # |
|
35 sub new |
|
36 { |
|
37 my $class = shift; |
|
38 my $object = $class->SUPER::new(); |
|
39 |
|
40 # Class members |
|
41 $object->{_OBJNAME} = "FeatureRegistry"; |
|
42 $object->{_FEAT_MAP} = {}; # Feature Info Hash map |
|
43 $object->{_FEAT_NAME_UID_MAP} = {}; # Hash map of feature name and uid |
|
44 return $object; |
|
45 } |
|
46 |
|
47 # |
|
48 # Private methods |
|
49 # |
|
50 |
|
51 # Private method to Get/Set the _FEAT_MAP member value of this class |
|
52 # @param : Feature Info Hash map (optional for GET) |
|
53 # |
|
54 my $featureHashMap = sub |
|
55 { |
|
56 my $object = shift; |
|
57 return 0 if(!&featureparser::ISREF($object,"featureHashMap")); |
|
58 |
|
59 if (@_) |
|
60 { |
|
61 $object->{_FEAT_MAP} = shift; |
|
62 } |
|
63 return $object->{_FEAT_MAP}; |
|
64 }; |
|
65 |
|
66 # |
|
67 # Public methods |
|
68 # |
|
69 |
|
70 # Get/Set the _FEAT_NAME_UID_MAP member value of this class |
|
71 # @param : Hash map of feature name and uid (optional for GET) |
|
72 # |
|
73 sub featureNameUidMap |
|
74 { |
|
75 my $object = shift; |
|
76 return 0 if(!&featureparser::ISREF($object,"featureNameUidMap")); |
|
77 |
|
78 if (@_) |
|
79 { |
|
80 $object->{_FEAT_NAME_UID_MAP} = shift; |
|
81 } |
|
82 return $object->{_FEAT_NAME_UID_MAP}; |
|
83 }; |
|
84 |
|
85 |
|
86 # Return the feature uid for the given feature name. |
|
87 # @param : Feature Name |
|
88 # |
|
89 sub getFeatureUID |
|
90 { |
|
91 my $object = shift; |
|
92 return 0 if(!&featureparser::ISREF($object,"getFeatureUID")); |
|
93 |
|
94 my $feature = shift; |
|
95 |
|
96 my $featureNameUidMap = $object->featureNameUidMap(); |
|
97 $feature = lc($feature); |
|
98 if(exists $featureNameUidMap->{$feature}){ |
|
99 return $featureNameUidMap->{$feature}; |
|
100 }else{ |
|
101 return undef; |
|
102 } |
|
103 } |
|
104 |
|
105 # Get the details of feature with given featureuid and other parameters |
|
106 # This function only consider the feature UID only and that UID should be in decimal |
|
107 # @param : Feature UID value |
|
108 # |
|
109 sub getFeatureInfo |
|
110 { |
|
111 my $object = shift; |
|
112 return 0 if(!&featureparser::ISREF($object,"getFeatureInfo")); |
|
113 |
|
114 my $uid = shift; |
|
115 my $featureMap = $object->$featureHashMap(); |
|
116 if(exists $featureMap->{$uid}) { |
|
117 return \%{$featureMap->{$uid}}; |
|
118 } |
|
119 else { |
|
120 return undef; |
|
121 } |
|
122 } |
|
123 |
|
124 # |
|
125 # Utility functions |
|
126 # |
|
127 |
|
128 # Update the feature hash map with the values from the xml feature registry file |
|
129 # |
|
130 sub createFeatureMap |
|
131 { |
|
132 my $object = shift; |
|
133 return 0 if(!&featureparser::ISREF($object,"createFeatureMap")); |
|
134 |
|
135 return 0 if($object->rootElement() < 0); |
|
136 |
|
137 # Get all <feature> Elements to @featureList |
|
138 my @featureList = &featureparser::getnodefromTree($object->rootElement(), "features", "feature"); |
|
139 |
|
140 if(@featureList) |
|
141 { |
|
142 my $featureNameUidMap = $object->featureNameUidMap(); |
|
143 my $featureMap = $object->$featureHashMap(); |
|
144 foreach my $node (@featureList) |
|
145 { |
|
146 # Define local variables to hold attribute names and values for each $node |
|
147 my $uid_value = &featureparser::getattrValue($node, "uid"); |
|
148 my $name_value = &featureparser::getattrValue($node, "name"); |
|
149 |
|
150 # Validate Name |
|
151 if(!$name_value) { |
|
152 &featureparser::ERROR("Feature name attribute is empty"); |
|
153 return 0; |
|
154 } |
|
155 |
|
156 # Validate UID |
|
157 if(&featureparser::IsValidNum($uid_value)) { |
|
158 $uid_value = &featureparser::ConvertHexToDecimal($uid_value); |
|
159 } |
|
160 else { |
|
161 &featureparser::ERROR("Valid hexadecimal or decimal value expected in UID entry for \"$name_value\""); |
|
162 return 0; |
|
163 } |
|
164 |
|
165 # Check the duplicate entry of feature |
|
166 if(exists $featureNameUidMap->{$name_value}) { |
|
167 &featureparser::ERROR("Feature entry \"".$name_value."\" already exists"); |
|
168 return 0; |
|
169 } |
|
170 if(exists $featureMap->{$uid_value}) { |
|
171 &featureparser::ERROR("UID entry for \"".$name_value."\" already exists"); |
|
172 return 0; |
|
173 } |
|
174 |
|
175 my $install_value = &featureparser::getattrValue($node, "installable"); |
|
176 if ($install_value eq undef) { |
|
177 $install_value = "false"; |
|
178 } |
|
179 |
|
180 # Store all key=values to global %featureHashMap & %featureNameUidMap |
|
181 $featureNameUidMap->{$name_value} = $uid_value; |
|
182 $featureMap->{$uid_value}{"name"} = &featureparser::getattrValue($node, "name",1); |
|
183 $featureMap->{$uid_value}{"installable"} = $install_value; |
|
184 } |
|
185 return 1; |
|
186 } |
|
187 |
|
188 return 0; |
|
189 } |
|
190 |
|
191 # Read the <defaultfeaturerange> element |
|
192 # |
|
193 sub createDefaultRangeMap |
|
194 { |
|
195 my $object = shift; |
|
196 return 0 if(!&featureparser::ISREF($object,"createDefaultRangeMap")); |
|
197 |
|
198 # Return error if the rootelement reference is NULL |
|
199 return 0 if($object->rootElement() < 0); |
|
200 |
|
201 # Get all the <defaultfeaturerange> elements |
|
202 my @attrSet = &featureparser::getnodefromTree($object->rootElement(), "default", "range"); |
|
203 |
|
204 # Add the defaultfeaturerange elements into the object |
|
205 return &featureparser::createDefaultRangeMap($object,@attrSet); |
|
206 } |
|
207 |
|
208 sub readRangeAttributes |
|
209 { |
|
210 my ($object, $currNode, $range) = @_; |
|
211 return 0 if(!&featureparser::ISREF($object,"readRangeAttributes")); |
|
212 |
|
213 #Get the lower and higher uids |
|
214 $range->{min} = &featureparser::getattrValue($currNode, "min"); |
|
215 $range->{max} = &featureparser::getattrValue($currNode, "max"); |
|
216 |
|
217 #Read the support keyword |
|
218 $range->{support} = &featureparser::getattrValue($currNode, "support"); |
|
219 |
|
220 #Read the installable element |
|
221 $range->{installable} = &featureparser::getattrValue($currNode, "installable"); |
|
222 } |
|
223 |
|
224 1; |