src/share/vm/utilities/xmlstream.hpp

Mon, 09 Mar 2009 13:28:46 -0700

author
xdono
date
Mon, 09 Mar 2009 13:28:46 -0700
changeset 1014
0fbdb4381b99
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6814575: Update copyright year
Summary: Update copyright for files that have been modified in 2009, up to 03/09
Reviewed-by: katleman, tbell, ohair

duke@435 1 /*
duke@435 2 * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 class xmlStream;
duke@435 26 class defaultStream;
duke@435 27
duke@435 28 // Sub-stream for writing quoted text, as opposed to markup.
duke@435 29 // Characters written to this stream are subject to quoting,
duke@435 30 // as '<' => "&lt;", etc.
duke@435 31 class xmlTextStream : public outputStream {
duke@435 32 friend class xmlStream;
duke@435 33 friend class defaultStream; // tty
duke@435 34 private:
duke@435 35
duke@435 36 xmlStream* _outer_xmlStream;
duke@435 37
duke@435 38 xmlTextStream() { _outer_xmlStream = NULL; }
duke@435 39
duke@435 40 public:
duke@435 41 virtual void flush(); // _outer.flush();
duke@435 42 virtual void write(const char* str, size_t len); // _outer->write_text()
duke@435 43 };
duke@435 44
duke@435 45
duke@435 46 // Output stream for writing XML-structured logs.
duke@435 47 // To write markup, use special calls elem, head/tail, etc.
duke@435 48 // Use the xmlStream::text() stream to write unmarked text.
duke@435 49 // Text written that way will be quoted as necessary using '&lt;', etc.
duke@435 50 // Characters written directly to an xmlStream via print_cr, etc.,
duke@435 51 // are directly written to the encapsulated stream, xmlStream::out().
duke@435 52 // This can be used to produce markup directly, character by character.
duke@435 53 // (Such writes are not checked for markup syntax errors.)
duke@435 54
duke@435 55 class xmlStream : public outputStream {
duke@435 56 friend class defaultStream; // tty
duke@435 57 public:
duke@435 58 enum MarkupState { BODY, // after end_head() call, in text
duke@435 59 HEAD, // after begin_head() call, in attrs
duke@435 60 ELEM }; // after begin_elem() call, in attrs
duke@435 61
duke@435 62 protected:
duke@435 63 outputStream* _out; // file stream by which it goes
duke@435 64 julong _last_flush; // last position of flush
duke@435 65 MarkupState _markup_state; // where in the elem/head/tail dance
duke@435 66 outputStream* _text; // text stream
duke@435 67 xmlTextStream _text_init;
duke@435 68
duke@435 69 // for subclasses
duke@435 70 xmlStream() {}
duke@435 71 void initialize(outputStream* out);
duke@435 72
duke@435 73 // protect this from public use:
duke@435 74 outputStream* out() { return _out; }
duke@435 75
duke@435 76 // helpers for writing XML elements
duke@435 77 void va_tag(bool push, const char* format, va_list ap);
duke@435 78 virtual void see_tag(const char* tag, bool push) NOT_DEBUG({});
duke@435 79 virtual void pop_tag(const char* tag) NOT_DEBUG({});
duke@435 80
duke@435 81 #ifdef ASSERT
duke@435 82 // in debug mode, we verify matching of opening and closing tags
duke@435 83 int _element_depth; // number of unfinished elements
duke@435 84 char* _element_close_stack_high; // upper limit of down-growing stack
duke@435 85 char* _element_close_stack_low; // upper limit of down-growing stack
duke@435 86 char* _element_close_stack_ptr; // pointer of down-growing stack
duke@435 87 #endif
duke@435 88
duke@435 89 public:
duke@435 90 // creation
duke@435 91 xmlStream(outputStream* out) { initialize(out); }
duke@435 92 DEBUG_ONLY(virtual ~xmlStream();)
duke@435 93
duke@435 94 bool is_open() { return _out != NULL; }
duke@435 95
duke@435 96 // text output
duke@435 97 bool inside_attrs() { return _markup_state != BODY; }
duke@435 98
duke@435 99 // flushing
duke@435 100 virtual void flush(); // flushes out, sets _last_flush = count()
duke@435 101 virtual void write(const char* s, size_t len);
duke@435 102 void write_text(const char* s, size_t len); // used by xmlTextStream
duke@435 103 int unflushed_count() { return (int)(out()->count() - _last_flush); }
duke@435 104
duke@435 105 // writing complete XML elements
duke@435 106 void elem(const char* format, ...);
duke@435 107 void begin_elem(const char* format, ...);
duke@435 108 void end_elem(const char* format, ...);
duke@435 109 void end_elem();
duke@435 110 void head(const char* format, ...);
duke@435 111 void begin_head(const char* format, ...);
duke@435 112 void end_head(const char* format, ...);
duke@435 113 void end_head();
duke@435 114 void done(const char* format, ...); // xxx_done event, plus tail
duke@435 115 void done_raw(const char * kind);
duke@435 116 void tail(const char* kind);
duke@435 117
duke@435 118 // va_list versions
duke@435 119 void va_elem(const char* format, va_list ap);
duke@435 120 void va_begin_elem(const char* format, va_list ap);
duke@435 121 void va_head(const char* format, va_list ap);
duke@435 122 void va_begin_head(const char* format, va_list ap);
duke@435 123 void va_done(const char* format, va_list ap);
duke@435 124
duke@435 125 // write text (with quoting of special XML characters <>&'" etc.)
duke@435 126 outputStream* text() { return _text; }
duke@435 127 void text(const char* format, ...);
duke@435 128 void va_text(const char* format, va_list ap) {
duke@435 129 text()->vprint(format, ap);
duke@435 130 }
duke@435 131
duke@435 132 // commonly used XML attributes
duke@435 133 void stamp(); // stamp='1.234'
duke@435 134 void method(methodHandle m); // method='k n s' ...
duke@435 135 void klass(KlassHandle k); // klass='name'
duke@435 136 void name(symbolHandle s); // name='name'
duke@435 137 void object(const char* attr, Handle val);
duke@435 138
duke@435 139 // print the text alone (sans ''):
duke@435 140 void method_text(methodHandle m);
duke@435 141 void klass_text(KlassHandle k); // klass='name'
duke@435 142 void name_text(symbolHandle s); // name='name'
duke@435 143 void object_text(Handle x);
duke@435 144
duke@435 145 /* Example uses:
duke@435 146
duke@435 147 // Empty element, simple case.
duke@435 148 elem("X Y='Z'"); <X Y='Z'/> \n
duke@435 149
duke@435 150 // Empty element, general case.
duke@435 151 begin_elem("X Y='Z'"); <X Y='Z'
duke@435 152 ...attrs... ...attrs...
duke@435 153 end_elem(); />
duke@435 154
duke@435 155 // Compound element, simple case.
duke@435 156 head("X Y='Z'"); <X Y='Z'> \n
duke@435 157 ...body... ...body...
duke@435 158 tail("X"); </X> \n
duke@435 159
duke@435 160 // Compound element, general case.
duke@435 161 begin_head("X Y='Z'"); <X Y='Z'
duke@435 162 ...attrs... ...attrs...
duke@435 163 end_head(); > \n
duke@435 164 ...body... ...body...
duke@435 165 tail("X"); </X> \n
duke@435 166
duke@435 167 // Printf-style formatting:
duke@435 168 elem("X Y='%s'", "Z"); <X Y='Z'/> \n
duke@435 169
duke@435 170 */
duke@435 171
duke@435 172 };
duke@435 173
duke@435 174 // Standard log file, null if no logging is happening.
duke@435 175 extern xmlStream* xtty;
duke@435 176
duke@435 177 // Note: If ::xtty != NULL, ::tty == ::xtty->text().

mercurial