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