/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_UTILITIES_XMLSTREAM_HPP
#define SHARE_VM_UTILITIES_XMLSTREAM_HPP
#include "runtime/handles.hpp"
#include "utilities/ostream.hpp"
class xmlStream;
class defaultStream;
// Sub-stream for writing quoted text, as opposed to markup.
// Characters written to this stream are subject to quoting,
// as '<' => "<", etc.
friend class xmlStream;
friend class defaultStream; // tty
private:
public:
virtual void flush(); // _outer.flush();
};
// Output stream for writing XML-structured logs.
// Use the xmlStream::text() stream to write unmarked text.
// Text written that way will be quoted as necessary using '<', etc.
// Characters written directly to an xmlStream via print_cr, etc.,
// are directly written to the encapsulated stream, xmlStream::out().
// This can be used to produce markup directly, character by character.
// (Such writes are not checked for markup syntax errors.)
friend class defaultStream; // tty
public:
protected:
// for subclasses
xmlStream() {}
// protect this from public use:
// helpers for writing XML elements
#ifdef ASSERT
// in debug mode, we verify matching of opening and closing tags
#endif
public:
// creation
DEBUG_ONLY(virtual ~xmlStream();)
// text output
// flushing
virtual void flush(); // flushes out, sets _last_flush = count()
// writing complete XML elements
void begin_elem(const char* format, ...);
void end_elem();
void begin_head(const char* format, ...);
void end_head();
// va_list versions
// write text (with quoting of special XML characters <>&'" etc.)
}
// commonly used XML attributes
void stamp(); // stamp='1.234'
// print the text alone (sans ''):
void method_text(methodHandle m);
void object_text(Handle x);
/* Example uses:
// Empty element, simple case.
elem("X Y='Z'"); <X Y='Z'/> \n
// Empty element, general case.
begin_elem("X Y='Z'"); <X Y='Z'
...attrs... ...attrs...
end_elem(); />
// Compound element, simple case.
head("X Y='Z'"); <X Y='Z'> \n
...body... ...body...
tail("X"); </X> \n
// Compound element, general case.
begin_head("X Y='Z'"); <X Y='Z'
...attrs... ...attrs...
end_head(); > \n
...body... ...body...
tail("X"); </X> \n
// Printf-style formatting:
elem("X Y='%s'", "Z"); <X Y='Z'/> \n
*/
};
// Standard log file, null if no logging is happening.
// Note: If ::xtty != NULL, ::tty == ::xtty->text().
#endif // SHARE_VM_UTILITIES_XMLSTREAM_HPP