1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <precomp.h>
23 #include "hi_ary.hxx"
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/ploc_dir.hxx>
28 #include <ary/idl/i_gate.hxx>
29 #include <ary/idl/i_module.hxx>
30 #include <ary/idl/i_ce.hxx>
31 #include <ary/idl/i_type.hxx>
32 #include <ary/idl/ip_ce.hxx>
33 #include <ary/idl/ip_type.hxx>
34
35
36 inline const ary::idl::Gate &
gate() const37 AryAccess::gate() const
38 { return rGate; }
39
40 inline const ary::idl::CePilot &
ces() const41 AryAccess::ces() const
42 { return rGate.Ces(); }
43
44 inline const ary::idl::TypePilot &
types() const45 AryAccess::types() const
46 { return rGate.Types(); }
47
48 inline const ary::idl::Module *
find_SubModule(const ary::idl::Module & i_parent,const String & i_name) const49 AryAccess::find_SubModule( const ary::idl::Module & i_parent,
50 const String & i_name ) const
51 {
52 ary::idl::Ce_id
53 nModule = i_parent.Search_Name(i_name);
54 return ces().Search_Module(nModule);
55 }
56
57 bool
nextName(const char * & io_TextPtr,String & o_name) const58 AryAccess::nextName( const char * & io_TextPtr,
59 String & o_name ) const
60 {
61 if ( strncmp(io_TextPtr,"::", 2) == 0 )
62 io_TextPtr += 2;
63
64 const char * pEnd = strchr(io_TextPtr,':');
65 size_t nLen = pEnd == 0
66 ? strlen(io_TextPtr)
67 : pEnd - io_TextPtr;
68 o_name.assign(io_TextPtr, nLen);
69 io_TextPtr += nLen;
70
71 return nLen > 0;
72 }
73
74
75
AryAccess(const ary::idl::Gate & i_rGate)76 AryAccess::AryAccess( const ary::idl::Gate & i_rGate )
77 : rGate(i_rGate)
78 {
79 }
80
81 const ary::idl::Module &
GlobalNamespace() const82 AryAccess::GlobalNamespace() const
83 {
84 return ces().GlobalNamespace();
85 }
86
87 const ary::idl::Module &
Find_Module(ary::idl::Ce_id i_ce) const88 AryAccess::Find_Module( ary::idl::Ce_id i_ce ) const
89 {
90 return ces().Find_Module(i_ce);
91 }
92
93
94 const ary::idl::CodeEntity &
Find_Ce(ary::idl::Ce_id i_ce) const95 AryAccess::Find_Ce( ary::idl::Ce_id i_ce ) const
96 {
97 return ces().Find_Ce(i_ce);
98 }
99
100 const ary::idl::Type &
Find_Type(ary::idl::Type_id i_type) const101 AryAccess::Find_Type( ary::idl::Type_id i_type ) const
102 {
103 return types().Find_Type(i_type);
104 }
105
106 ary::idl::Ce_id
CeFromType(ary::idl::Type_id i_type) const107 AryAccess::CeFromType( ary::idl::Type_id i_type ) const
108 {
109 return types().Search_CeRelatedTo(i_type);
110 }
111
112 bool
IsBuiltInOrRelated(const ary::idl::Type & i_type) const113 AryAccess::IsBuiltInOrRelated( const ary::idl::Type & i_type ) const
114 {
115 return types().IsBuiltInOrRelated(i_type);
116 }
117
118 bool
Search_Ce(StringVector & o_module,String & o_mainEntity,String & o_memberEntity,const char * i_sText,const ary::idl::Module & i_referingScope) const119 AryAccess::Search_Ce( StringVector & o_module,
120 String & o_mainEntity,
121 String & o_memberEntity,
122 const char * i_sText,
123 const ary::idl::Module & i_referingScope ) const
124 {
125 o_module.erase(o_module.begin(),o_module.end());
126 o_mainEntity = String::Null_();
127 o_memberEntity = String::Null_();
128
129 const ary::idl::Module * pModule = 0;
130
131 if ( strncmp(i_sText, "::", 2) == 0
132 OR strncmp(i_sText, "com::sun::star", 14) == 0 )
133 pModule = &GlobalNamespace();
134 else
135 {
136 pModule = &i_referingScope;
137 ces().Get_Text(o_module, o_mainEntity, o_memberEntity, *pModule);
138 }
139
140 const char * pNext = i_sText;
141 String sNextName;
142
143 // Find Module:
144 while ( nextName(pNext, sNextName) )
145 {
146 const ary::idl::Module *
147 pSub = find_SubModule(*pModule, sNextName);
148 if (pSub != 0)
149 {
150 pModule = pSub;
151 o_module.push_back(sNextName);
152 }
153 else
154 break;
155 }
156
157 // Find main CodeEntity:
158 if ( sNextName.length() == 0 )
159 return true;
160 const ary::idl::Ce_id
161 nCe = pModule->Search_Name(sNextName);
162 if (NOT nCe.IsValid())
163 return false;
164 o_mainEntity = sNextName;
165
166 // Find member:
167 if ( *pNext == 0 )
168 return true;
169 nextName(pNext, o_memberEntity);
170 if (strchr(o_memberEntity,':') != 0)
171 return false; // This must not happen in IDL
172
173 #if 0
174 // The following code avoids false links, but is rather expensive
175 // in runtime time consumation.
176
177 const ary::idl::CodeEntity *
178 pCe = Find_Ce(nCe);
179 if (pCe == 0)
180 return false;
181
182 if ( NOT ary::idl::ifc_ce::attr::Search_Member(*pCe,o_memberEntity) )
183 return false;
184 #endif
185
186 return true;
187 }
188
189 bool
Search_CesModule(StringVector & o_module,const String & i_scope,const String & i_ce,const ary::idl::Module & i_referingScope) const190 AryAccess::Search_CesModule( StringVector & o_module,
191 const String & i_scope,
192 const String & i_ce,
193 const ary::idl::Module & i_referingScope ) const
194 {
195 o_module.erase(o_module.begin(),o_module.end());
196
197 const ary::idl::Module *
198 pModule = 0;
199
200 if ( strncmp(i_scope, "::", 2) == 0
201 OR strncmp(i_scope, "com::sun::star", 14) == 0 )
202 pModule = &GlobalNamespace();
203 else
204 {
205 pModule = &i_referingScope;
206 static String Dummy1;
207 static String Dummy2;
208 ces().Get_Text(o_module, Dummy1, Dummy2, *pModule);
209 }
210
211 const char * pNext = i_scope;
212 String sNextName;
213
214 // Find Module:
215 while ( nextName(pNext, sNextName) )
216 {
217 const ary::idl::Module *
218 pSub = find_SubModule(*pModule, sNextName);
219 if (pSub != 0)
220 {
221 pModule = pSub;
222 o_module.push_back(sNextName);
223 }
224 else
225 return false;
226 } // end while
227 return pModule->Search_Name(i_ce).IsValid();
228 }
229
230 const ary::idl::Module *
Search_Module(const StringVector & i_nameChain) const231 AryAccess::Search_Module( const StringVector & i_nameChain ) const
232 {
233 const ary::idl::Module * ret =
234 &GlobalNamespace();
235 for ( StringVector::const_iterator it = i_nameChain.begin();
236 it != i_nameChain.end();
237 ++it )
238 {
239 ret = find_SubModule(*ret, *it);
240 if (ret == 0)
241 break;
242 } // end for
243 return ret;
244 }
245
246 void
Get_CeText(StringVector & o_module,String & o_ce,String & o_member,const ary::idl::CodeEntity & i_ce) const247 AryAccess::Get_CeText( StringVector & o_module,
248 String & o_ce,
249 String & o_member,
250 const ary::idl::CodeEntity & i_ce ) const
251 {
252 ces().Get_Text(o_module, o_ce, o_member, i_ce);
253 }
254
255 void
Get_TypeText(StringVector & o_module,String & o_sCe,ary::idl::Ce_id & o_nCe,int & o_sequenceCount,const ary::idl::Type & i_type) const256 AryAccess::Get_TypeText( StringVector & o_module,
257 String & o_sCe,
258 ary::idl::Ce_id & o_nCe,
259 int & o_sequenceCount,
260 const ary::idl::Type & i_type ) const
261 {
262 i_type.Get_Text(o_module, o_sCe, o_nCe, o_sequenceCount, gate());
263 }
264
265 void
Get_IndexData(std::vector<ary::idl::Ce_id> & o_data,ary::idl::alphabetical_index::E_Letter i_letter) const266 AryAccess::Get_IndexData( std::vector<ary::idl::Ce_id> & o_data,
267 ary::idl::alphabetical_index::E_Letter i_letter ) const
268 {
269 rGate.Ces().Get_AlphabeticalIndex(o_data, i_letter);
270 }
271
272
273 const ary::idl::CePilot &
Ces() const274 AryAccess::Ces() const
275 {
276 return rGate.Ces();
277 }
278