| 418 | } |
| 419 | |
| 420 | void ExtensionContainer::restoreExtensions(Base::XMLReader& reader) |
| 421 | { |
| 422 | |
| 423 | // Dynamic extensions are optional (also because they are introduced late into the document |
| 424 | // format) and hence it is possible that the element does not exist. As we cannot check for the |
| 425 | // existence of an element a object attribute is set if extensions are available. Here we check |
| 426 | // that attribute, and only if it exists the extensions element will be available. |
| 427 | if (!reader.hasAttribute("Extensions")) { |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | reader.readElement("Extensions"); |
| 432 | int Cnt = reader.getAttribute<long>("Count"); |
| 433 | |
| 434 | for (int i = 0; i < Cnt; i++) { |
| 435 | reader.readElement("Extension"); |
| 436 | const char* Type = reader.getAttribute<const char*>("type"); |
| 437 | const char* Name = reader.getAttribute<const char*>("name"); |
| 438 | try { |
| 439 | App::Extension* ext = getExtension(Name); |
| 440 | if (!ext) { |
| 441 | // get the extension type asked for |
| 442 | Base::Type extension = Base::Type::fromName(Type); |
| 443 | if (extension.isBad() |
| 444 | || !extension.isDerivedFrom(App::Extension::getExtensionClassTypeId())) { |
| 445 | std::stringstream str; |
| 446 | str << "No extension found of type '" << Type << "'" << std::ends; |
| 447 | throw Base::TypeError(str.str()); |
| 448 | } |
| 449 | |
| 450 | // register the extension |
| 451 | ext = static_cast<App::Extension*>(extension.createInstance()); |
| 452 | // check if this really is a python extension! |
| 453 | if (!ext->isPythonExtension()) { |
| 454 | delete ext; |
| 455 | std::stringstream str; |
| 456 | str << "Extension is not a python addable version: '" << Type << "'"; |
| 457 | throw Base::TypeError(str.str()); |
| 458 | } |
| 459 | |
| 460 | ext->initExtension(this); |
| 461 | } |
| 462 | if (ext && ext->getExtensionTypeId().getName() == Type) { |
| 463 | ext->extensionRestore(reader); |
| 464 | } |
| 465 | } |
| 466 | catch (const Base::XMLParseException&) { |
| 467 | throw; // re-throw |
| 468 | } |
| 469 | catch (const Base::Exception& e) { |
| 470 | Base::Console().error("%s\n", e.what()); |
| 471 | } |
| 472 | catch (const std::exception& e) { |
| 473 | Base::Console().error("%s\n", e.what()); |
| 474 | } |
| 475 | catch (const char* e) { |
| 476 | Base::Console().error("%s\n", e); |
| 477 | } |
nothing calls this directly
no test coverage detected