2 * Copyright 2001-2009 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file xmltooling/util/ReloadableXMLFile.h
20 * Base class for file-based XML configuration.
23 #ifndef __xmltooling_reloadable_h__
24 #define __xmltooling_reloadable_h__
26 #include <xmltooling/logging.h>
27 #include <xmltooling/Lockable.h>
31 #include <xercesc/dom/DOM.hpp>
33 namespace xmltooling {
35 class XMLTOOL_API RWLock;
38 * Base class for file-based XML configuration.
40 class XMLTOOL_API ReloadableXMLFile : protected virtual Lockable
42 MAKE_NONCOPYABLE(ReloadableXMLFile);
45 * Constructor taking a DOM element supporting the following content:
48 * <dt>file | filename | path | pathname</dt>
49 * <dd>identifies a local file</dd>
51 * <dd>identifies a remote resource</dd>
53 * <dd>use a validating parser</dd>
54 * <dt>reloadChanges</dt>
55 * <dd>enables monitoring of local file for changes</dd>
56 * <dt>reloadInterval</dt>
57 * <dd>enables periodic refresh of remote file</dd>
58 * <dt>backingFilePath</dt>
59 * <dd>location for backup of remote resource</dd>
62 * @param e DOM to supply configuration
63 * @param log logging object to use
65 ReloadableXMLFile(const xercesc::DOMElement* e, logging::Category& log);
67 virtual ~ReloadableXMLFile();
70 * Loads configuration material.
72 * <p>This method is called to load configuration material
73 * initially and any time a change is detected. The base version
74 * performs basic parsing duties and returns the result.
76 * @return a pair consisting of a flag indicating whether to take ownership of
77 * the document, and the root element of the tree to load
79 virtual std::pair<bool,xercesc::DOMElement*> load();
81 /** Root of the original DOM element passed into constructor. */
82 const xercesc::DOMElement* m_root;
84 /** Indicates whether resources is local or remote. */
87 /** Use a validating parser when parsing XML. */
90 /** Resource location, may be a local path or a URI. */
93 /** Path to backup copy for remote resource. */
94 std::string m_backing;
96 /** Last modification of local resource or reload of remote resource. */
99 /** Time in seconds to wait before trying for new copy of remote resource. */
100 time_t m_reloadInterval;
102 /** Caching tag associated with remote resource. */
103 std::string m_cacheTag;
105 /** Shared lock for guarding reloads. */
108 /** Logging object. */
109 logging::Category& m_log;
116 std::pair<bool,xercesc::DOMElement*> load(bool backup);
121 #endif /* __xmltooling_reloadable_h__ */