|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "mdenamespacedef.h" |
|
20 |
|
21 #include "mdcdef.h" |
|
22 #include "mdeobjectdef.h" |
|
23 #include "mderelationdef.h" |
|
24 #include "mdeeventdef.h" |
|
25 #include "mdcserializationbuffer.h" |
|
26 |
|
27 |
|
28 CMdENamespaceDef::CMdENamespaceDef( const CMdESession& aMdeSession, |
|
29 const TMdCNamespaceDef& aNamespaceDef ) |
|
30 : iMdeSession( aMdeSession ), iNamespaceDef( aNamespaceDef ) |
|
31 { |
|
32 } |
|
33 |
|
34 CMdENamespaceDef* CMdENamespaceDef::NewL( const CMdESession& aMdeSession, |
|
35 const TMdCNamespaceDef& aNamespaceDef, |
|
36 CMdCSerializationBuffer& aSchemaBuffer ) |
|
37 { |
|
38 CMdENamespaceDef* def = CMdENamespaceDef::NewLC( aMdeSession, |
|
39 aNamespaceDef, aSchemaBuffer ); |
|
40 CleanupStack::Pop( def ); |
|
41 return def; |
|
42 } |
|
43 |
|
44 CMdENamespaceDef* CMdENamespaceDef::NewLC( const CMdESession& aMdeSession, |
|
45 const TMdCNamespaceDef& aNamespaceDef, |
|
46 CMdCSerializationBuffer& aSchemaBuffer ) |
|
47 { |
|
48 CMdENamespaceDef* def = new( ELeave ) CMdENamespaceDef( aMdeSession, |
|
49 aNamespaceDef ); |
|
50 CleanupStack::PushL( def ); |
|
51 def->ConstructL( aSchemaBuffer ); |
|
52 return def; |
|
53 } |
|
54 |
|
55 void CMdENamespaceDef::ConstructL(CMdCSerializationBuffer& aSchemaBuffer) |
|
56 { |
|
57 aSchemaBuffer.PositionL( iNamespaceDef.iName.iPtr.iOffset ); |
|
58 iName.Set( aSchemaBuffer.ReceivePtr16L() ); |
|
59 |
|
60 TUint32 count = iNamespaceDef.iObjectDefs.iPtr.iCount; |
|
61 TMdCOffset offset = iNamespaceDef.iObjectDefs.iPtr.iOffset; |
|
62 iObjectDefs.ReserveL( count ); |
|
63 for ( TUint32 i = 0; i < count; ++i ) |
|
64 { |
|
65 aSchemaBuffer.PositionL( offset + i * sizeof(TMdCObjectDef) ); |
|
66 const TMdCObjectDef& objectDef = TMdCObjectDef::GetFromBufferL(aSchemaBuffer); |
|
67 iObjectDefs.AppendL( CMdEObjectDef::NewL( objectDef, aSchemaBuffer, *this ) ); |
|
68 } |
|
69 |
|
70 count = iNamespaceDef.iEventDefs.iPtr.iCount; |
|
71 offset = iNamespaceDef.iEventDefs.iPtr.iOffset; |
|
72 iEventDefs.ReserveL( count ); |
|
73 for ( TUint32 i = 0; i < count; ++i ) |
|
74 { |
|
75 aSchemaBuffer.PositionL( offset + i * sizeof(TMdCEventDef) ); |
|
76 const TMdCEventDef& eventDef = TMdCEventDef::GetFromBufferL(aSchemaBuffer); |
|
77 iEventDefs.AppendL( CMdEEventDef::NewL( eventDef, aSchemaBuffer, *this ) ); |
|
78 } |
|
79 |
|
80 count = iNamespaceDef.iRelationDefs.iPtr.iCount; |
|
81 offset = iNamespaceDef.iRelationDefs.iPtr.iOffset; |
|
82 iRelationDefs.ReserveL( count ); |
|
83 for ( TUint32 i = 0; i < count; ++i ) |
|
84 { |
|
85 aSchemaBuffer.PositionL( offset + i * sizeof(TMdCRelationDef) ); |
|
86 const TMdCRelationDef& relationDef = TMdCRelationDef::GetFromBufferL(aSchemaBuffer); |
|
87 iRelationDefs.AppendL( CMdERelationDef::NewL( relationDef, aSchemaBuffer, *this ) ); |
|
88 } |
|
89 } |
|
90 |
|
91 CMdENamespaceDef::~CMdENamespaceDef() |
|
92 { |
|
93 |
|
94 iObjectDefs.ResetAndDestroy(); |
|
95 iObjectDefs.Close(); |
|
96 |
|
97 iEventDefs.ResetAndDestroy(); |
|
98 iEventDefs.Close(); |
|
99 |
|
100 iRelationDefs.ResetAndDestroy(); |
|
101 iRelationDefs.Close(); |
|
102 } |
|
103 |
|
104 TDefId CMdENamespaceDef::Id() const |
|
105 { |
|
106 return iNamespaceDef.iDefId; |
|
107 } |
|
108 |
|
109 EXPORT_C TBool CMdENamespaceDef::ReadOnly() const |
|
110 { |
|
111 return iNamespaceDef.iReadOnly; |
|
112 } |
|
113 |
|
114 EXPORT_C const TDesC& CMdENamespaceDef::Name() const |
|
115 { |
|
116 return iName; |
|
117 } |
|
118 |
|
119 EXPORT_C TInt CMdENamespaceDef::Compare( const CMdENamespaceDef& aNamespaceDef ) const |
|
120 { |
|
121 return iNamespaceDef.iDefId - aNamespaceDef.Id(); |
|
122 } |
|
123 |
|
124 EXPORT_C TInt CMdENamespaceDef::ObjectDefCount() const |
|
125 { |
|
126 return iObjectDefs.Count(); |
|
127 } |
|
128 |
|
129 EXPORT_C CMdEObjectDef& CMdENamespaceDef::ObjectDefL(TInt aIndex) |
|
130 { |
|
131 return *iObjectDefs[aIndex]; |
|
132 } |
|
133 |
|
134 EXPORT_C CMdEObjectDef& CMdENamespaceDef::GetObjectDefL(const TDesC& aName) |
|
135 { |
|
136 const TInt objectDefsCount = iObjectDefs.Count(); |
|
137 for ( TInt i = 0; i < objectDefsCount; ++i ) |
|
138 { |
|
139 if ( !aName.Compare( iObjectDefs[i]->Name() ) ) |
|
140 { |
|
141 return ObjectDefL( i ); |
|
142 } |
|
143 } |
|
144 |
|
145 User::Leave( KErrNotFound ); |
|
146 |
|
147 // to stop compile warnings |
|
148 CMdEObjectDef* objectDef = NULL; |
|
149 return *objectDef; |
|
150 } |
|
151 |
|
152 CMdEObjectDef* CMdENamespaceDef::GetObjectDefL(TDefId aId) |
|
153 { |
|
154 const TInt objectDefsCount = iObjectDefs.Count(); |
|
155 for ( TInt i = 0; i < objectDefsCount; ++i ) |
|
156 { |
|
157 if ( aId == iObjectDefs[i]->Id() ) |
|
158 { |
|
159 return &ObjectDefL( i ); |
|
160 } |
|
161 } |
|
162 |
|
163 return NULL; |
|
164 } |
|
165 |
|
166 EXPORT_C TInt CMdENamespaceDef::RelationDefCount() const |
|
167 { |
|
168 return iRelationDefs.Count(); |
|
169 } |
|
170 |
|
171 EXPORT_C CMdERelationDef& CMdENamespaceDef::RelationDefL(TInt aIndex) |
|
172 { |
|
173 return *iRelationDefs[aIndex]; |
|
174 } |
|
175 |
|
176 EXPORT_C CMdERelationDef& CMdENamespaceDef::GetRelationDefL(const TDesC& aName) |
|
177 { |
|
178 const TInt relationDefCount = iRelationDefs.Count(); |
|
179 for ( TInt i = 0; i < relationDefCount; ++i ) |
|
180 { |
|
181 if( !aName.Compare( iRelationDefs[i]->Name() ) ) |
|
182 { |
|
183 return RelationDefL( i ); |
|
184 } |
|
185 } |
|
186 |
|
187 User::Leave( KErrNotFound ); |
|
188 |
|
189 // to stop compile warnings |
|
190 CMdERelationDef* relationDef = NULL; |
|
191 return *relationDef; |
|
192 } |
|
193 |
|
194 CMdERelationDef* CMdENamespaceDef::GetRelationDefL(TDefId aId) |
|
195 { |
|
196 const TInt relationDefCount = iRelationDefs.Count(); |
|
197 for ( TInt i = 0; i < relationDefCount; ++i ) |
|
198 { |
|
199 if( iRelationDefs[i]->Id() == aId ) |
|
200 { |
|
201 return &RelationDefL( i ); |
|
202 } |
|
203 } |
|
204 |
|
205 return NULL; |
|
206 } |
|
207 |
|
208 EXPORT_C TInt CMdENamespaceDef::EventDefCount() const |
|
209 { |
|
210 return iEventDefs.Count(); |
|
211 } |
|
212 |
|
213 EXPORT_C CMdEEventDef& CMdENamespaceDef::EventDefL(TInt aIndex) |
|
214 { |
|
215 return *iEventDefs[aIndex]; |
|
216 } |
|
217 |
|
218 EXPORT_C CMdEEventDef& CMdENamespaceDef::GetEventDefL(const TDesC& aName) |
|
219 { |
|
220 const TInt eventDefCount = iEventDefs.Count(); |
|
221 for ( TInt i = 0; i < eventDefCount; ++i ) |
|
222 { |
|
223 if( !aName.Compare( iEventDefs[i]->Name() ) ) |
|
224 { |
|
225 return EventDefL( i ); |
|
226 } |
|
227 } |
|
228 |
|
229 User::Leave( KErrNotFound ); |
|
230 |
|
231 // to stop compile warnings |
|
232 CMdEEventDef* eventDef = NULL; |
|
233 return *eventDef; |
|
234 } |
|
235 |
|
236 CMdEEventDef* CMdENamespaceDef::GetEventDefL(TDefId aId) |
|
237 { |
|
238 const TInt eventDefCount = iEventDefs.Count(); |
|
239 for ( TInt i = 0; i < eventDefCount; ++i ) |
|
240 { |
|
241 if( iEventDefs[i]->Id() == aId ) |
|
242 { |
|
243 return &EventDefL( i ); |
|
244 } |
|
245 } |
|
246 return NULL; |
|
247 } |
|
248 |
|
249 const CMdESession& CMdENamespaceDef::Session() const |
|
250 { |
|
251 return iMdeSession; |
|
252 } |