View Javadoc

1   // SECTION-START[License Header]
2   // <editor-fold defaultstate="collapsed" desc=" Generated License ">
3   /*
4    *   Java Object Management and Configuration
5    *   Copyright (C) Christian Schulte, 2005-206
6    *   All rights reserved.
7    *
8    *   Redistribution and use in source and binary forms, with or without
9    *   modification, are permitted provided that the following conditions
10   *   are met:
11   *
12   *     o Redistributions of source code must retain the above copyright
13   *       notice, this list of conditions and the following disclaimer.
14   *
15   *     o Redistributions in binary form must reproduce the above copyright
16   *       notice, this list of conditions and the following disclaimer in
17   *       the documentation and/or other materials provided with the
18   *       distribution.
19   *
20   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
21   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
24   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30   *
31   *   $JOMC: TestObjectManagementListener.java 4588 2012-06-03 06:01:30Z schulte2005 $
32   *
33   */
34  // </editor-fold>
35  // SECTION-END
36  package org.jomc.ri.test.support;
37  
38  import java.io.OutputStream;
39  import java.io.PrintWriter;
40  import java.util.logging.Level;
41  
42  // SECTION-START[Documentation]
43  // <editor-fold defaultstate="collapsed" desc=" Generated Documentation ">
44  /**
45   * {@code ObjectManagementLister} logging to the console.
46   *
47   * <dl>
48   *   <dt><b>Identifier:</b></dt><dd>JOMC :: RI :: Tests :: Test Object Management Listener</dd>
49   *   <dt><b>Name:</b></dt><dd>JOMC RI</dd>
50   *   <dt><b>Specifications:</b></dt>
51   *     <dd>org.jomc.spi.Listener @ 1.0</dd>
52   *   <dt><b>Abstract:</b></dt><dd>No</dd>
53   *   <dt><b>Final:</b></dt><dd>No</dd>
54   *   <dt><b>Stateless:</b></dt><dd>No</dd>
55   * </dl>
56   *
57   * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a> 1.0
58   * @version 1.3
59   */
60  // </editor-fold>
61  // SECTION-END
62  // SECTION-START[Annotations]
63  // <editor-fold defaultstate="collapsed" desc=" Generated Annotations ">
64  @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" )
65  // </editor-fold>
66  // SECTION-END
67  public class TestObjectManagementListener
68      implements
69      org.jomc.spi.Listener
70  {
71      // SECTION-START[TestObjectManagementListener]
72  
73      /** The {@code OutputStream} to stream to. */
74      private OutputStream outputStream;
75  
76      /** The {@code PrintWriter} events are printed with. */
77      private PrintWriter printWriter;
78  
79      /**
80       * Gets the output stream events are streamed to.
81       *
82       * @return The output stream events are streamed to.
83       */
84      public OutputStream getOutputStream()
85      {
86          if ( this.outputStream == null )
87          {
88              this.outputStream = System.out;
89          }
90  
91          return this.outputStream;
92      }
93  
94      /**
95       * Gets the print writer events are printed with,
96       *
97       * @return The print writer events are printed with.
98       */
99      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.3", comments = "See http://jomc.sourceforge.net/jomc/1.3/jomc-tools-1.3" )
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 }