Ejemplo n.º 1
0
 /// <summary>
 /// This method calls <code>flush</code>, writes the closing
 /// postamble and then closes the output stream associated
 /// with this stream.
 /// </summary>
 public virtual void Close()
 {
     Flush();
     Writeln("</java>");
     try
     {
         @out.Close();
     }
     catch (IOException e)
     {
         ExceptionListener.ExceptionThrown(e);
     }
 }
Ejemplo n.º 2
0
 private void Close(Closeable @in)
 {
     if (@in != null)
     {
         try
         {
             @in.Close();
         }
         catch (IOException e)
         {
             ExceptionListener.ExceptionThrown(e);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This method writes out the preamble associated with the
        /// XML encoding if it has not been written already and
        /// then writes out all of the values that been
        /// written to the stream since the last time <code>flush</code>
        /// was called. After flushing, all internal references to the
        /// values that were written to this stream are cleared.
        /// </summary>
        public virtual void Flush()
        {
            if (!PreambleWritten)             // Don't do this in constructor - it throws ... pending.
            {
                if (this.Declaration)
                {
                    Writeln("<?xml version=" + Quote("1.0") + " encoding=" + Quote(this.Charset) + "?>");
                }
                Writeln("<java version=" + Quote(System.getProperty("java.version")) + " class=" + Quote(typeof(XMLDecoder).Name) + ">");
                PreambleWritten = true;
            }
            Indentation++;
            List <Statement> statements = StatementList(this);

            while (statements.Count > 0)
            {
                Statement s = statements.Remove(0);
                if ("writeObject".Equals(s.MethodName))
                {
                    OutputValue(s.Arguments[0], this, true);
                }
                else
                {
                    OutputStatement(s, this, false);
                }
            }
            Indentation--;

            Statement statement = MissedStatement;

            while (statement != null)
            {
                OutputStatement(statement, this, false);
                statement = MissedStatement;
            }

            try
            {
                @out.Flush();
            }
            catch (IOException e)
            {
                ExceptionListener.ExceptionThrown(e);
            }
            Clear();
        }
Ejemplo n.º 4
0
 private void Writeln(String exp)
 {
     try
     {
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < Indentation; i++)
         {
             sb.Append(' ');
         }
         sb.Append(exp);
         sb.Append('\n');
         [email protected](sb.ToString());
     }
     catch (IOException e)
     {
         ExceptionListener.ExceptionThrown(e);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Records the Statement so that the Encoder will
        /// produce the actual output when the stream is flushed.
        /// <P>
        /// This method should only be invoked within the context
        /// of initializing a persistence delegate.
        /// </summary>
        /// <param name="oldStm"> The statement that will be written
        ///               to the stream. </param>
        /// <seealso cref= java.beans.PersistenceDelegate#initialize </seealso>
        public override void WriteStatement(Statement oldStm)
        {
            // System.out.println("XMLEncoder::writeStatement: " + oldStm);
            bool @internal = this.@internal;

            this.@internal = true;
            try
            {
                base.WriteStatement(oldStm);

                /*
                 * Note we must do the mark first as we may
                 * require the results of previous values in
                 * this context for this statement.
                 * Test case is:
                 *     os.setOwner(this);
                 *     os.writeObject(this);
                 */
                Mark(oldStm);
                Object target = oldStm.Target;
                if (target is Field)
                {
                    String   method = oldStm.MethodName;
                    Object[] args   = oldStm.Arguments;
                    if ((method == null) || (args == null))
                    {
                    }
                    else if (method.Equals("get") && (args.Length == 1))
                    {
                        target = args[0];
                    }
                    else if (method.Equals("set") && (args.Length == 2))
                    {
                        target = args[0];
                    }
                }
                StatementList(target).Add(oldStm);
            }
            catch (Exception e)
            {
                ExceptionListener.ExceptionThrown(new Exception("XMLEncoder: discarding statement " + oldStm, e));
            }
            this.@internal = @internal;
        }