1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <precomp.h>
29 #include "hi_ary.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <cosv/ploc_dir.hxx>
34 #include <ary/idl/i_gate.hxx>
35 #include <ary/idl/i_module.hxx>
36 #include <ary/idl/i_ce.hxx>
37 #include <ary/idl/i_type.hxx>
38 #include <ary/idl/ip_ce.hxx>
39 #include <ary/idl/ip_type.hxx>
40 
41 
42 inline const ary::idl::Gate &
43 AryAccess::gate() const
44     { return rGate; }
45 
46 inline const ary::idl::CePilot &
47 AryAccess::ces() const
48     { return rGate.Ces(); }
49 
50 inline const ary::idl::TypePilot &
51 AryAccess::types() const
52     { return rGate.Types(); }
53 
54 inline const ary::idl::Module *
55 AryAccess::find_SubModule( const ary::idl::Module & i_parent,
56                            const String &			i_name ) const
57 {
58     ary::idl::Ce_id
59         nModule = i_parent.Search_Name(i_name);
60     return ces().Search_Module(nModule);
61 }
62 
63 bool
64 AryAccess::nextName( const char * &      io_TextPtr,
65                      String &            o_name ) const
66 {
67     if ( strncmp(io_TextPtr,"::", 2) == 0 )
68         io_TextPtr += 2;
69 
70     const char *    pEnd = strchr(io_TextPtr,':');
71     size_t          nLen = pEnd == 0
72                                 ?   strlen(io_TextPtr)
73                                 :   pEnd - io_TextPtr;
74     o_name.assign(io_TextPtr, nLen);
75     io_TextPtr += nLen;
76 
77     return nLen > 0;
78 }
79 
80 
81 
82 AryAccess::AryAccess( const ary::idl::Gate & i_rGate )
83     :   rGate(i_rGate)
84 {
85 }
86 
87 const ary::idl::Module &
88 AryAccess::GlobalNamespace() const
89 {
90     return ces().GlobalNamespace();
91 }
92 
93 const ary::idl::Module &
94 AryAccess::Find_Module( ary::idl::Ce_id i_ce ) const
95 {
96     return ces().Find_Module(i_ce);
97 }
98 
99 
100 const ary::idl::CodeEntity &
101 AryAccess::Find_Ce( ary::idl::Ce_id i_ce ) const
102 {
103     return ces().Find_Ce(i_ce);
104 }
105 
106 const ary::idl::Type &
107 AryAccess::Find_Type( ary::idl::Type_id i_type ) const
108 {
109     return types().Find_Type(i_type);
110 }
111 
112 ary::idl::Ce_id
113 AryAccess::CeFromType( ary::idl::Type_id i_type ) const
114 {
115     return types().Search_CeRelatedTo(i_type);
116 }
117 
118 bool
119 AryAccess::IsBuiltInOrRelated( const ary::idl::Type & i_type ) const
120 {
121     return types().IsBuiltInOrRelated(i_type);
122 }
123 
124 bool
125 AryAccess::Search_Ce( StringVector &            o_module,
126                       String &                  o_mainEntity,
127                       String &                  o_memberEntity,
128                       const char *              i_sText,
129                       const ary::idl::Module &  i_referingScope ) const
130 {
131     o_module.erase(o_module.begin(),o_module.end());
132     o_mainEntity = String::Null_();
133     o_memberEntity = String::Null_();
134 
135     const ary::idl::Module *    pModule = 0;
136 
137     if ( strncmp(i_sText, "::", 2) == 0
138          OR strncmp(i_sText, "com::sun::star", 14) == 0 )
139         pModule = &GlobalNamespace();
140     else
141     {
142         pModule = &i_referingScope;
143         ces().Get_Text(o_module, o_mainEntity, o_memberEntity, *pModule);
144     }
145 
146     const char *    pNext = i_sText;
147     String          sNextName;
148 
149     // Find Module:
150     while ( nextName(pNext, sNextName) )
151     {
152         const ary::idl::Module *
153             pSub = find_SubModule(*pModule, sNextName);
154         if (pSub != 0)
155         {
156             pModule = pSub;
157             o_module.push_back(sNextName);
158         }
159         else
160             break;
161     }
162 
163     // Find main CodeEntity:
164     if ( sNextName.length() == 0 )
165         return true;
166     const ary::idl::Ce_id
167         nCe = pModule->Search_Name(sNextName);
168     if (NOT nCe.IsValid())
169         return false;
170     o_mainEntity = sNextName;
171 
172     // Find member:
173     if ( *pNext == 0 )
174         return true;
175 	nextName(pNext, o_memberEntity);
176     if (strchr(o_memberEntity,':') != 0)
177         return false;   // This must not happen in IDL
178 
179 #if 0
180 // The following code avoids false links, but is rather expensive
181 //   in runtime time consumation.
182 
183     const ary::idl::CodeEntity *
184         pCe = Find_Ce(nCe);
185     if (pCe == 0)
186         return false;
187 
188     if ( NOT ary::idl::ifc_ce::attr::Search_Member(*pCe,o_memberEntity) )
189         return false;
190 #endif
191 
192     return true;
193 }
194 
195 bool
196 AryAccess::Search_CesModule( StringVector &             o_module,
197                              const String &             i_scope,
198                              const String &             i_ce,
199                              const ary::idl::Module &   i_referingScope ) const
200 {
201     o_module.erase(o_module.begin(),o_module.end());
202 
203     const ary::idl::Module *
204         pModule = 0;
205 
206     if ( strncmp(i_scope, "::", 2) == 0
207          OR strncmp(i_scope, "com::sun::star", 14) == 0 )
208         pModule = &GlobalNamespace();
209     else
210     {
211         pModule = &i_referingScope;
212         static String Dummy1;
213         static String Dummy2;
214         ces().Get_Text(o_module, Dummy1, Dummy2, *pModule);
215     }
216 
217     const char *    pNext = i_scope;
218     String          sNextName;
219 
220     // Find Module:
221     while ( nextName(pNext, sNextName) )
222     {
223         const ary::idl::Module *
224             pSub = find_SubModule(*pModule, sNextName);
225         if (pSub != 0)
226         {
227             pModule = pSub;
228             o_module.push_back(sNextName);
229         }
230         else
231             return false;
232     }  // end while
233     return pModule->Search_Name(i_ce).IsValid();
234 }
235 
236 const ary::idl::Module *
237 AryAccess::Search_Module( const StringVector & i_nameChain ) const
238 {
239     const ary::idl::Module * ret =
240         &GlobalNamespace();
241     for ( StringVector::const_iterator it = i_nameChain.begin();
242           it != i_nameChain.end();
243           ++it )
244     {
245         ret = find_SubModule(*ret, *it);
246         if (ret == 0)
247             break;
248     }   // end for
249     return ret;
250 }
251 
252 void
253 AryAccess::Get_CeText( StringVector &               o_module,
254                        String &                     o_ce,
255                        String &                     o_member,
256                        const ary::idl::CodeEntity & i_ce ) const
257 {
258     ces().Get_Text(o_module, o_ce, o_member, i_ce);
259 }
260 
261 void
262 AryAccess::Get_TypeText( StringVector &         o_module,
263                          String &               o_sCe,
264                          ary::idl::Ce_id &      o_nCe,
265                          int &                  o_sequenceCount,
266                          const ary::idl::Type & i_type ) const
267 {
268     i_type.Get_Text(o_module, o_sCe, o_nCe, o_sequenceCount, gate());
269 }
270 
271 void
272 AryAccess::Get_IndexData( std::vector<ary::idl::Ce_id> &            o_data,
273                           ary::idl::alphabetical_index::E_Letter    i_letter ) const
274 {
275     rGate.Ces().Get_AlphabeticalIndex(o_data, i_letter);
276 }
277 
278 
279 const ary::idl::CePilot &
280 AryAccess::Ces() const
281 {
282     return rGate.Ces();
283 }
284