|
1 /* |
|
2 * Copyright (c) 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 "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 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #include "wspolicyreader.h" |
|
24 |
|
25 #include "policyassertion.h" |
|
26 #include "andcompositeassertion.h" |
|
27 #include "xorcompositeassertion.h" |
|
28 #include "assertion.h" |
|
29 #include "primitiveassertion.h" |
|
30 #include "policyreferenceassertion.h" |
|
31 |
|
32 using namespace WSPolicy; |
|
33 |
|
34 CWSPolicyReader* CWSPolicyReader::NewL() |
|
35 { |
|
36 CWSPolicyReader* pSelf = CWSPolicyReader::NewLC(); |
|
37 CleanupStack::Pop(pSelf); |
|
38 return pSelf; |
|
39 |
|
40 } |
|
41 CWSPolicyReader* CWSPolicyReader::NewLC() |
|
42 { |
|
43 CWSPolicyReader* pSelf = new (ELeave) CWSPolicyReader(); |
|
44 CleanupStack::PushL(pSelf); |
|
45 pSelf->ConstructL(); |
|
46 return pSelf; |
|
47 |
|
48 } |
|
49 CWSPolicyReader::~CWSPolicyReader() |
|
50 { |
|
51 } |
|
52 CWSPolicyReader::CWSPolicyReader() |
|
53 { |
|
54 } |
|
55 void CWSPolicyReader::ConstructL() |
|
56 { |
|
57 } |
|
58 |
|
59 CPolicyAssertion* CWSPolicyReader::GetPolicyL(CSenElement* aPolicy) |
|
60 { |
|
61 CPolicyAssertion* policy = ReadPolicyL(aPolicy); |
|
62 if(policy) |
|
63 return policy; |
|
64 else |
|
65 return NULL; |
|
66 } |
|
67 |
|
68 |
|
69 //PRIVATE METHODS |
|
70 CPolicyAssertion* CWSPolicyReader::ReadPolicyL(CSenElement* aEle) |
|
71 { |
|
72 if(!aEle) |
|
73 return NULL; |
|
74 |
|
75 CPolicyAssertion* policy = CPolicyAssertion::NewL(); |
|
76 |
|
77 TPtrC8 kwsuid(KWsuId); |
|
78 TPtrC8 id = GetAttribL(kwsuid, aEle); |
|
79 if (id != KNullDesC8()) |
|
80 { |
|
81 policy->SetIdL(id); |
|
82 } |
|
83 |
|
84 RPointerArray<MAssertion> terms; |
|
85 ReadTermsL(aEle, terms); |
|
86 policy->AddTerms(terms); |
|
87 terms.Reset(); |
|
88 |
|
89 return policy; |
|
90 |
|
91 } |
|
92 CAndCompositeAssertion* CWSPolicyReader::ReadAndAssertionL(CSenElement* aEle) |
|
93 { |
|
94 CAndCompositeAssertion* andAssert = CAndCompositeAssertion::NewL(); |
|
95 |
|
96 RPointerArray<MAssertion> terms; |
|
97 ReadTermsL(aEle, terms); |
|
98 andAssert->AddTerms(terms); |
|
99 terms.Reset(); |
|
100 return andAssert; |
|
101 |
|
102 } |
|
103 CXorCompositeAssertion* CWSPolicyReader::ReadXorAssertionL(CSenElement* aEle) |
|
104 { |
|
105 CXorCompositeAssertion* xorAssert = CXorCompositeAssertion::NewL(); |
|
106 |
|
107 RPointerArray<MAssertion> terms; |
|
108 ReadTermsL(aEle, terms); |
|
109 xorAssert->AddTerms(terms); |
|
110 terms.Reset(); |
|
111 return xorAssert; |
|
112 |
|
113 } |
|
114 CAssertion* CWSPolicyReader::ReadAssertionL(CSenElement* aEle) |
|
115 { |
|
116 TPtrC8 nsUri = aEle->NamespaceURI(); |
|
117 TPtrC8 localName = aEle->LocalName(); |
|
118 |
|
119 if(nsUri.Length() == 0 || localName.Length() == 0) |
|
120 return NULL; |
|
121 |
|
122 if (!(nsUri == KWsPolicyNsUri)) |
|
123 { |
|
124 return ReadPrimitiveAssertionL(aEle); |
|
125 } |
|
126 |
|
127 if (localName == KWsPolicy) |
|
128 { |
|
129 return ReadPolicyL(aEle); |
|
130 |
|
131 } |
|
132 else if (localName == KAndCompositeAssertion) |
|
133 { |
|
134 return ReadAndAssertionL(aEle); |
|
135 |
|
136 } |
|
137 else if (localName == KXorCompositeAssertion) |
|
138 { |
|
139 return ReadXorAssertionL(aEle); |
|
140 |
|
141 } |
|
142 else if (localName == KWsPolicyReference ) |
|
143 { |
|
144 return ReadPolicyReferenceL(aEle); |
|
145 |
|
146 } |
|
147 else |
|
148 { |
|
149 return NULL; |
|
150 } |
|
151 } |
|
152 CPolicyReferenceAssertion* CWSPolicyReader::ReadPolicyReferenceL(CSenElement* aEle) |
|
153 { |
|
154 |
|
155 TPtrC8 id = GetAttribL(KUri(), aEle); |
|
156 if(id.Length() > 0) |
|
157 { |
|
158 return CPolicyReferenceAssertion::NewL(id); |
|
159 } |
|
160 return NULL; |
|
161 } |
|
162 CPrimitiveAssertion* CWSPolicyReader::ReadPrimitiveAssertionL(CSenElement* aEle) |
|
163 { |
|
164 TPtrC8 localName = aEle->LocalName();//GetQname |
|
165 TPtrC8 nsprefix = aEle->NsPrefix(); |
|
166 TPtrC8 nsuri= aEle->NamespaceURI(); |
|
167 |
|
168 if(localName.Length() == 0 || nsprefix.Length() == 0 || nsuri.Length() == 0) |
|
169 return NULL; |
|
170 |
|
171 CPrimitiveAssertion* result = CPrimitiveAssertion::NewL(localName,nsprefix,nsuri); |
|
172 |
|
173 RAttributeMap attribs(ETrue,ETrue); |
|
174 GetAttributesL(aEle, attribs); |
|
175 result->SetAttributesL(attribs); |
|
176 attribs.Reset(); |
|
177 |
|
178 |
|
179 TPtrC8 isOptional = result->GetAttributeValue(KWspOptinal); |
|
180 |
|
181 if(isOptional == KWspOptinalTrue) |
|
182 { |
|
183 result->SetOptional(ETrue); |
|
184 } |
|
185 else if(isOptional == KWspOptinalFalse) |
|
186 { |
|
187 result->SetOptional(EFalse); |
|
188 result->RemoveAttribute(KWspOptinal); |
|
189 } |
|
190 |
|
191 // setting the text value .. |
|
192 if(aEle->HasContent()) |
|
193 { |
|
194 TPtrC8 strValue = aEle->Content(); |
|
195 if(strValue != KNullDesC8()) |
|
196 |
|
197 result->SetStrValueL(strValue); |
|
198 } |
|
199 |
|
200 |
|
201 RPointerArray<CSenElement> childElements = aEle->ElementsL(); |
|
202 for (TInt i=0; i<childElements.Count(); i++ ) |
|
203 { |
|
204 CSenElement* childElement = childElements[i]; |
|
205 if(childElement && childElement->LocalName() == KWsPolicy |
|
206 && childElement->NamespaceURI() == KWsPolicyNsUri) |
|
207 { |
|
208 CPolicyAssertion* policy = ReadPolicyL(childElement); |
|
209 result->AddTerm(policy); |
|
210 |
|
211 } |
|
212 else |
|
213 { |
|
214 CPrimitiveAssertion* pa = ReadPrimitiveAssertionL(childElement); |
|
215 result->AddTerm(pa); |
|
216 } |
|
217 } |
|
218 |
|
219 return result; |
|
220 |
|
221 } |
|
222 void CWSPolicyReader::ReadTermsL(CSenElement* aEle, RPointerArray<MAssertion>& aTerms) |
|
223 { |
|
224 RPointerArray<CSenElement> childElements = aEle->ElementsL(); |
|
225 for (TInt i=0; i<childElements.Count(); i++ ) |
|
226 { |
|
227 CSenElement* obj = childElements[i]; |
|
228 if(obj) |
|
229 { |
|
230 MAssertion* ass = ReadAssertionL(obj); |
|
231 if(ass) |
|
232 { |
|
233 aTerms.Append(ass); |
|
234 } |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 void CWSPolicyReader::GetAttributesL(CSenElement* aEle, RAttributeMap& aAttributes) |
|
240 { |
|
241 RPointerArray<CSenBaseAttribute> attribs = aEle->AttributesL(); |
|
242 for (TInt i=0; i<attribs.Count(); i++ ) |
|
243 { |
|
244 CSenBaseAttribute* obj = attribs[i]; |
|
245 if(obj) |
|
246 { |
|
247 TPtrC8 name = obj->Name(); |
|
248 TPtrC8 value = obj->Value(); |
|
249 |
|
250 aAttributes.Append(name.AllocL(), value.AllocL()); |
|
251 } |
|
252 } |
|
253 } |
|
254 |
|
255 TPtrC8 CWSPolicyReader::GetAttribL(TPtrC8 aReference, CSenElement* aEle) |
|
256 { |
|
257 |
|
258 RPointerArray<CSenBaseAttribute>& attrs = aEle->AttributesL(); |
|
259 |
|
260 CSenBaseAttribute* bs = NULL; |
|
261 TInt ele_count = attrs.Count(); |
|
262 |
|
263 for (TInt j=0; j < ele_count; j++) |
|
264 { |
|
265 |
|
266 bs = (attrs)[j]; |
|
267 if(bs->Name().Compare(aReference) == 0) |
|
268 { |
|
269 return bs->Value(); |
|
270 } |
|
271 |
|
272 |
|
273 } |
|
274 return KNullDesC8(); |
|
275 } |
|
276 //EOF |