Project Report: fawkez

Packagesummary org.jcoderz.commons

org.jcoderz.commons.BaseRuntimeException

LineHitsNoteSource
1  /*
2   * $Id: BaseRuntimeException.java 1492 2009-06-06 13:36:19Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons;
34  
35  
36  import java.io.Serializable;
37  import java.util.List;
38  import java.util.Set;
39  import java.util.logging.Logger;
40  
41  
42  /**
43   * This is the Base class for all runtime exceptions.
44   *
45   * <p>In the {@link org.jcoderz.commons package overview} you can find a
46   * general statement when to use runtime exceptions.</p>
47   *
48   * <p>This class can never be directly used. Services must implement a
49   * general service specific Exception from which they can derive more
50   * concrete service specific exceptions. There are some common used
51   * exceptions available as direct subclasses of this class. If
52   * appropriate this classes must be used prior generating own
53   * classes.</p>
54   *
55   * <p>Most functionality is implemented and documented by the
56   * {@link org.jcoderz.commons.LoggableImpl} which is used a member of
57   * objects of this class. Other stuff is handled by the base class
58   * {@link java.lang.Exception}.</p>
59   *
60   *
61   * @see org.jcoderz.commons
62   * @author Andreas Mandel
63   */
64  public class BaseRuntimeException
65        extends RuntimeException
66        implements Loggable
67  {
68     private static final long serialVersionUID = 2L;
6975    private static final String CLASSNAME = BaseRuntimeException.class.getName();
70100    private static final Logger LOGGER = Logger.getLogger(CLASSNAME);
71  
72     /** The loggable implementation. */
73     private final LoggableImpl mLoggable;
74  
75     /**
76      * Constructor getting an log message info.
77      *
78      * @param messageInfo the log message info for this exception
79      */
80     protected BaseRuntimeException (LogMessageInfo messageInfo)
81     {
82100       super(messageInfo.getSymbol());
83100       mLoggable = new LoggableImpl(this, messageInfo);
84100    }
85  
86     /**
87      * Constructor getting an log message info and a root exception.
88      *
89      * @param messageInfo the log message info for this exception
90      * @param cause the problem that caused this exception to be thrown
91      */
92     protected BaseRuntimeException (LogMessageInfo messageInfo, Throwable cause)
93     {
94100       super(messageInfo.getSymbol(), cause);
95100       mLoggable = new LoggableImpl(this, messageInfo, cause);
96100    }
97  
98     /** {@inheritDoc} */
99     public Throwable initCause (Throwable cause)
100     {
1010       super.initCause(cause);
1020       mLoggable.initCause(cause);
1030       return this;
104     }
105  
106     /** {@inheritDoc} */
107     public final void addParameter (String name, Serializable value)
108     {
109100       mLoggable.addParameter(name, value);
110100    }
111  
112     /** {@inheritDoc} */
113     public String getInstanceId ()
114     {
115100       return mLoggable.getInstanceId();
116     }
117  
118     /** {@inheritDoc} */
119     public final String getMessage ()
120     {
121100       return mLoggable.getMessage();
122     }
123  
124     /** {@inheritDoc} */
125     public final void log ()
126     {
127100       mLoggable.log();
128100    }
129  
130     /** {@inheritDoc} */
131     public Throwable getCause ()
132     {
133100       return mLoggable.getCause();
134     }
135  
136     /** {@inheritDoc} */
137     public long getEventTime ()
138     {
139100       return mLoggable.getEventTime();
140     }
141  
142     /** {@inheritDoc} */
143     public LogMessageInfo getLogMessageInfo ()
144     {
145100       return mLoggable.getLogMessageInfo();
146     }
147  
148     /** {@inheritDoc} */
149     public String getNodeId ()
150     {
151100       return mLoggable.getNodeId();
152     }
153  
154     /** {@inheritDoc} */
155     public List getParameter (String name)
156     {
157100       return mLoggable.getParameter(name);
158     }
159  
160     /** {@inheritDoc} */
161     public Set getParameterNames ()
162     {
163100       return mLoggable.getParameterNames();
164     }
165  
166     /** {@inheritDoc} */
167     public long getThreadId ()
168     {
169100       return mLoggable.getThreadId();
170     }
171  
172     /** {@inheritDoc} */
173     public String getTrackingNumber ()
174     {
175100       return mLoggable.getTrackingNumber();
176     }
177  
178     /** {@inheritDoc} */
179     public String getSourceClass ()
180     {
1810       return mLoggable.getSourceClass();
182     }
183  
184     /** {@inheritDoc} */
185     public String getSourceMethod ()
186     {
1870       return mLoggable.getSourceMethod();
188     }
189  
190     /** {@inheritDoc} */
191     public String getThreadName ()
192     {
193100        return mLoggable.getThreadName();
194     }
195  
196     /** {@inheritDoc} */
197     public String toString ()
198     {
199100       return mLoggable.toString();
200     }
201  
202     /** {@inheritDoc} */
203     public String toDetailedString ()
204     {
2050       return mLoggable.toDetailedString();
206     }
207  
208     protected final void logCreation ()
209     {
210100        if (LOGGER.isLoggable(
211             RteLogMessage.RuntimeExceptionCreated.LOG_LEVEL))
212         {
213100            final LogEvent logEvent
214                 = new LogEvent(RteLogMessage.RUNTIME_EXCEPTION_CREATED, this);
215100            RteLogMessage.ExceptionCreated.addParameters(
216                 logEvent, mLoggable.getLogMessageInfo().getSymbol(),
217                 mLoggable.getMessage());
218100            LOGGER.logp(logEvent.getLogMessageInfo().getLogLevel(),
219                 logEvent.getSourceClass(), logEvent.getSourceMethod(),
220                 logEvent.getMessage(), logEvent);
221         }
222100    }
223  
224     LoggableImpl getExceptionImpl ()
225     {
2260       return mLoggable;
227     }
228  
229  }

Findings in this File

f (1) Copied and pasted code. 301 equal tokens (120 lines) found in 2 locations. See also: org.jcoderz.commons.BaseException:93 Delegation code can not be externalized further.