< prev index next >

src/java.desktop/share/classes/java/beans/XMLEncoder.java

Print this page




 176  * with a "property" attribute whose value is given by removing
 177  * the "set" prefix and decapitalizing the result.
 178  * <li>
 179  * In an element representing a method named "get" taking one
 180  * integer argument, the "method" attribute is replaced
 181  * with an "index" attribute whose value the value of the
 182  * first argument.
 183  * <li>
 184  * In an element representing a method named "set" taking two arguments,
 185  * the first of which is an integer, the "method" attribute is replaced
 186  * with an "index" attribute whose value the value of the
 187  * first argument.
 188  * <li>
 189  * A reference to an array is written using the "array"
 190  * tag. The "class" and "length" attributes specify the
 191  * sub-type of the array and its length respectively.
 192  * </ul>
 193  *
 194  *<p>
 195  * For more information you might also want to check out
 196  * <a
 197  href="http://java.sun.com/products/jfc/tsc/articles/persistence4">Using XMLEncoder</a>,
 198  * an article in <em>The Swing Connection.</em>
 199  * @see XMLDecoder
 200  * @see java.io.ObjectOutputStream
 201  *
 202  * @since 1.4
 203  *
 204  * @author Philip Milne
 205  */
 206 public class XMLEncoder extends Encoder implements AutoCloseable {
 207 
 208     private final CharsetEncoder encoder;
 209     private final String charset;
 210     private final boolean declaration;
 211 
 212     private OutputStreamWriter out;
 213     private Object owner;
 214     private int indentation = 0;
 215     private boolean internal = false;
 216     private Map<Object, ValueData> valueToExpression;
 217     private Map<Object, List<Statement>> targetToStatementList;


 421             }
 422             statementList(target).add(oldStm);
 423         }
 424         catch (Exception e) {
 425             getExceptionListener().exceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e));
 426         }
 427         this.internal = internal;
 428     }
 429 
 430 
 431     /**
 432      * Records the Expression so that the Encoder will
 433      * produce the actual output when the stream is flushed.
 434      * <P>
 435      * This method should only be invoked within the context of
 436      * initializing a persistence delegate or setting up an encoder to
 437      * read from a resource bundle.
 438      * <P>
 439      * For more information about using resource bundles with the
 440      * XMLEncoder, see
 441      * http://java.sun.com/products/jfc/tsc/articles/persistence4/#i18n

 442      *
 443      * @param oldExp The expression that will be written
 444      *               to the stream.
 445      * @see java.beans.PersistenceDelegate#initialize
 446      */
 447     public void writeExpression(Expression oldExp) {
 448         boolean internal = this.internal;
 449         this.internal = true;
 450         Object oldValue = getValue(oldExp);
 451         if (get(oldValue) == null || (oldValue instanceof String && !internal)) {
 452             getValueData(oldValue).exp = oldExp;
 453             super.writeExpression(oldExp);
 454         }
 455         this.internal = internal;
 456     }
 457 
 458     /**
 459      * This method writes out the preamble associated with the
 460      * XML encoding if it has not been written already and
 461      * then writes out all of the values that been




 176  * with a "property" attribute whose value is given by removing
 177  * the "set" prefix and decapitalizing the result.
 178  * <li>
 179  * In an element representing a method named "get" taking one
 180  * integer argument, the "method" attribute is replaced
 181  * with an "index" attribute whose value the value of the
 182  * first argument.
 183  * <li>
 184  * In an element representing a method named "set" taking two arguments,
 185  * the first of which is an integer, the "method" attribute is replaced
 186  * with an "index" attribute whose value the value of the
 187  * first argument.
 188  * <li>
 189  * A reference to an array is written using the "array"
 190  * tag. The "class" and "length" attributes specify the
 191  * sub-type of the array and its length respectively.
 192  * </ul>
 193  *
 194  *<p>
 195  * For more information you might also want to check out
 196  * <a href="http://www.oracle.com/technetwork/java/persistence4-140124.html">
 197  * Using XMLEncoder</a>,
 198  * an article in <em>The Swing Connection.</em>
 199  * @see XMLDecoder
 200  * @see java.io.ObjectOutputStream
 201  *
 202  * @since 1.4
 203  *
 204  * @author Philip Milne
 205  */
 206 public class XMLEncoder extends Encoder implements AutoCloseable {
 207 
 208     private final CharsetEncoder encoder;
 209     private final String charset;
 210     private final boolean declaration;
 211 
 212     private OutputStreamWriter out;
 213     private Object owner;
 214     private int indentation = 0;
 215     private boolean internal = false;
 216     private Map<Object, ValueData> valueToExpression;
 217     private Map<Object, List<Statement>> targetToStatementList;


 421             }
 422             statementList(target).add(oldStm);
 423         }
 424         catch (Exception e) {
 425             getExceptionListener().exceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e));
 426         }
 427         this.internal = internal;
 428     }
 429 
 430 
 431     /**
 432      * Records the Expression so that the Encoder will
 433      * produce the actual output when the stream is flushed.
 434      * <P>
 435      * This method should only be invoked within the context of
 436      * initializing a persistence delegate or setting up an encoder to
 437      * read from a resource bundle.
 438      * <P>
 439      * For more information about using resource bundles with the
 440      * XMLEncoder, see
 441      * <a href="http://www.oracle.com/technetwork/java/persistence4-140124.html#i18n">
 442      * Creating Internationalized Applications</a>,
 443      *
 444      * @param oldExp The expression that will be written
 445      *               to the stream.
 446      * @see java.beans.PersistenceDelegate#initialize
 447      */
 448     public void writeExpression(Expression oldExp) {
 449         boolean internal = this.internal;
 450         this.internal = true;
 451         Object oldValue = getValue(oldExp);
 452         if (get(oldValue) == null || (oldValue instanceof String && !internal)) {
 453             getValueData(oldValue).exp = oldExp;
 454             super.writeExpression(oldExp);
 455         }
 456         this.internal = internal;
 457     }
 458 
 459     /**
 460      * This method writes out the preamble associated with the
 461      * XML encoding if it has not been written already and
 462      * then writes out all of the values that been


< prev index next >