Update copyright.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ReloadableXMLFile.cpp
index 3aab81a..a0213b5 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- *  Copyright 2001-2005 Internet2\r
+ *  Copyright 2001-2007 Internet2\r
  * \r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -91,7 +91,7 @@ ReloadableXMLFile::ReloadableXMLFile(const DOMElement* e)
         }\r
 \r
         flag=e->getAttributeNS(NULL,reloadChanges);\r
-        if (!flag || XMLString::equals(flag,xmlconstants::XML_TRUE) || XMLString::equals(flag,xmlconstants::XML_ONE)) {\r
+        if (!XMLString::equals(flag,xmlconstants::XML_FALSE) && !XMLString::equals(flag,xmlconstants::XML_ZERO)) {\r
             if (m_local) {\r
 #ifdef WIN32\r
                 struct _stat stat_buf;\r
@@ -158,12 +158,12 @@ pair<bool,DOMElement*> ReloadableXMLFile::load()
     }\r
     catch (XMLException& e) {\r
         auto_ptr_char msg(e.getMessage());\r
-        log.errorStream() << "Xerces error while loading resource (" << m_source << "): "\r
+        log.critStream() << "Xerces error while loading resource (" << m_source << "): "\r
             << msg.get() << CategoryStream::ENDLINE;\r
         throw XMLParserException(msg.get());\r
     }\r
-    catch (XMLToolingException& e) {\r
-        log.errorStream() << "error while loading configuration from ("\r
+    catch (exception& e) {\r
+        log.critStream() << "error while loading configuration from ("\r
             << (m_source.empty() ? "inline" : m_source) << "): " << e.what() << CategoryStream::ENDLINE;\r
         throw;\r
     }\r
@@ -202,6 +202,7 @@ Lockable* ReloadableXMLFile::lock()
 \r
         // Update the timestamp regardless. No point in repeatedly trying.\r
         m_filestamp=stat_buf.st_mtime;\r
+        Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").info("change detected, reloading local resource...");\r
     }\r
     else {\r
         if (isValid())\r
@@ -216,16 +217,21 @@ Lockable* ReloadableXMLFile::lock()
             m_lock->rdlock();\r
             return this;\r
         }\r
+        Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").info("local copy invalid, reloading remote resource...");\r
     }\r
     \r
     // Do this once...\r
-    do {\r
+    try {\r
         // At this point we're holding the write lock, so make sure we pop it.\r
         SharedLock lockwrap(m_lock,false);\r
         pair<bool,DOMElement*> ret=load();\r
         if (ret.first)\r
             ret.second->getOwnerDocument()->release();\r
-    } while(0);\r
+    } catch (exception& ex) {\r
+        Category::getInstance(XMLTOOLING_LOGCAT".ReloadableXMLFile").crit(\r
+            "maintaining existing configuration, error reloading resource (%s): %s", m_source.c_str(), ex.what()\r
+            );\r
+    }\r
     \r
     // If we made it here, the swap may or may not have worked, but we need to relock.\r
     m_lock->rdlock();\r