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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_codemaker.hxx"
26 
27 #include "codemaker/exceptiontree.hxx"
28 #include "codemaker/typemanager.hxx"
29 
30 #include "osl/diagnose.h"
31 #include "registry/reader.hxx"
32 #include "registry/types.h"
33 #include "rtl/string.hxx"
34 #include "rtl/textenc.h"
35 #include "rtl/ustring.hxx"
36 
37 #include <memory>
38 #include <vector>
39 
40 using codemaker::ExceptionTree;
41 using codemaker::ExceptionTreeNode;
42 
add(rtl::OString const & theName)43 ExceptionTreeNode * ExceptionTreeNode::add(rtl::OString const & theName) {
44     std::auto_ptr< ExceptionTreeNode > node(new ExceptionTreeNode(theName));
45     children.push_back(node.get());
46     return node.release();
47 }
48 
clearChildren()49 void ExceptionTreeNode::clearChildren() {
50     for (Children::iterator i(children.begin()); i != children.end(); ++i) {
51         delete *i;
52     }
53     children.clear();
54 }
55 
add(rtl::OString const & name,TypeManager const & manager)56 void ExceptionTree::add(rtl::OString const & name, TypeManager const & manager)
57     throw( CannotDumpException )
58 {
59     typedef std::vector< rtl::OString > List;
60     List list;
61     bool runtimeException = false;
62     for (rtl::OString n(name); n != "com/sun/star/uno/Exception";) {
63         if (n == "com/sun/star/uno/RuntimeException") {
64             runtimeException = true;
65             break;
66         }
67         list.push_back(n);
68         typereg::Reader reader(manager.getTypeReader(n));
69         if (!reader.isValid())
70             throw CannotDumpException(
71                 ::rtl::OString("Unknown type '" + n.replace('/', '.')
72                                + "', incomplete type library."));
73 
74         OSL_ASSERT(
75             reader.getTypeClass() == RT_TYPE_EXCEPTION
76             && reader.getSuperTypeCount() == 1);
77         n = rtl::OUStringToOString(
78             reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8);
79     }
80     if (!runtimeException) {
81         ExceptionTreeNode * node = &m_root;
82         for (List::reverse_iterator i(list.rbegin()); !node->present; ++i) {
83             if (i == list.rend()) {
84                 node->setPresent();
85                 break;
86             }
87             for (ExceptionTreeNode::Children::iterator j(
88                      node->children.begin());;
89                  ++j)
90             {
91                 if (j == node->children.end()) {
92                     node = node->add(*i);
93                     break;
94                 }
95                 if ((*j)->name == *i) {
96                     node = *j;
97                     break;
98                 }
99             }
100         }
101     }
102 }
103