001    // SECTION-START[License Header]
002    // <editor-fold defaultstate="collapsed" desc=" Generated License ">
003    /*
004     *   Java Object Management and Configuration
005     *   Copyright (C) Christian Schulte, 2005-206
006     *   All rights reserved.
007     *
008     *   Redistribution and use in source and binary forms, with or without
009     *   modification, are permitted provided that the following conditions
010     *   are met:
011     *
012     *     o Redistributions of source code must retain the above copyright
013     *       notice, this list of conditions and the following disclaimer.
014     *
015     *     o Redistributions in binary form must reproduce the above copyright
016     *       notice, this list of conditions and the following disclaimer in
017     *       the documentation and/or other materials provided with the
018     *       distribution.
019     *
020     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
021     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
022     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
023     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
024     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
025     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
026     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
027     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
028     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
029     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030     *
031     *   $JOMC: TestObjectManagementListener.java 4459 2012-03-27 23:55:31Z schulte2005 $
032     *
033     */
034    // </editor-fold>
035    // SECTION-END
036    package org.jomc.ri.test.support;
037    
038    import java.io.OutputStream;
039    import java.io.PrintWriter;
040    import java.util.logging.Level;
041    
042    // SECTION-START[Documentation]
043    // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
044    /**
045     * {@code ObjectManagementLister} logging to the console.
046     *
047     * <dl>
048     *   <dt><b>Identifier:</b></dt><dd>JOMC :: RI :: Tests :: Test Object Management Listener</dd>
049     *   <dt><b>Name:</b></dt><dd>JOMC RI</dd>
050     *   <dt><b>Specifications:</b></dt>
051     *     <dd>org.jomc.spi.Listener @ 1.0</dd>
052     *   <dt><b>Abstract:</b></dt><dd>No</dd>
053     *   <dt><b>Final:</b></dt><dd>No</dd>
054     *   <dt><b>Stateless:</b></dt><dd>No</dd>
055     * </dl>
056     *
057     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
058     * @version 1.2.2
059     */
060    // </editor-fold>
061    // SECTION-END
062    // SECTION-START[Annotations]
063    // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
064    @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
065    // </editor-fold>
066    // SECTION-END
067    public class TestObjectManagementListener
068        implements
069        org.jomc.spi.Listener
070    {
071        // SECTION-START[TestObjectManagementListener]
072    
073        /** The {@code OutputStream} to stream to. */
074        private OutputStream outputStream;
075    
076        /** The {@code PrintWriter} events are printed with. */
077        private PrintWriter printWriter;
078    
079        /**
080         * Gets the output stream events are streamed to.
081         *
082         * @return The output stream events are streamed to.
083         */
084        public OutputStream getOutputStream()
085        {
086            if ( this.outputStream == null )
087            {
088                this.outputStream = System.out;
089            }
090    
091            return this.outputStream;
092        }
093    
094        /**
095         * Gets the print writer events are printed with,
096         *
097         * @return The print writer events are printed with.
098         */
099        public PrintWriter getPrintWriter()
100        {
101            if ( this.printWriter == null )
102            {
103                this.printWriter = new PrintWriter( this.getOutputStream(), true );
104            }
105    
106            return this.printWriter;
107        }
108    
109        /**
110         * Sets the print writer to print events with,
111         *
112         * @param value The new print writer to print events with,
113         */
114        public void setPrintWriter( final PrintWriter value )
115        {
116            this.printWriter = value;
117        }
118    
119        /**
120         * Sets the output stream to stream events to.
121         *
122         * @param value The new output stream to stream events to.
123         */
124        public void setOutputStream( final OutputStream value )
125        {
126            this.outputStream = value;
127        }
128    
129        // SECTION-END
130        // SECTION-START[Listener]
131        public void onLog( final Level level, final String message, final Throwable throwable )
132        {
133            if ( message != null )
134            {
135                this.getPrintWriter().print( "[JOMC] " );
136                this.getPrintWriter().print( "[" + level.getLocalizedName() + "] " );
137                this.getPrintWriter().println( message );
138            }
139            if ( throwable != null )
140            {
141                this.getPrintWriter().print( "[JOMC] " );
142                this.getPrintWriter().print( "[" + level.getLocalizedName() + "] " );
143                this.getPrintWriter().println( throwable );
144            }
145        }
146    
147        // SECTION-END
148        // SECTION-START[Constructors]
149        // <editor-fold defaultstate="collapsed" desc=" Generated Constructors ">
150        /** Creates a new {@code TestObjectManagementListener} instance. */
151        @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
152        public TestObjectManagementListener()
153        {
154            // SECTION-START[Default Constructor]
155            super();
156            // SECTION-END
157        }
158        // </editor-fold>
159        // SECTION-END
160        // SECTION-START[Dependencies]
161        // SECTION-END
162        // SECTION-START[Properties]
163        // SECTION-END
164        // SECTION-START[Messages]
165        // SECTION-END
166    }