Project Report: fawkez

Packagesummary org.jcoderz.commons

org.jcoderz.commons.BaseException

LineHitsNoteSource
1  /*
2   * $Id: BaseException.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 checked exceptions.
44   *
45   * <p>In the {@link org.jcoderz.commons package overview} you can find a
46   * general statement when to use checked exceptions.</p>
47   *
48   * <p>This class can never be directly used. Services must implement a
49   * general service specific Exception (generated initially by the service
50   * framework code generator) from which they can derive more concrete
51   * service specific exceptions. There are some common used exceptions
52   * available as direct subclasses of this class. If appropriate this
53   * classes must be used prior generating own 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 BaseException
65        extends Exception
66        implements Loggable
67  {
68     private static final long serialVersionUID = 2L;
6975    private static final String CLASSNAME = BaseException.class.getName();
70100    private static final Logger LOGGER = Logger.getLogger(CLASSNAME);
71  
72  
73     /** The loggable implementation. */
74     private final LoggableImpl mLoggable;
75  
76     /**
77      * Constructor getting an log message info.
78      *
79      * @param messageInfo the log message info for this exception
80      */
81     protected BaseException (LogMessageInfo messageInfo)
82     {
83100       super(messageInfo.getSymbol());
84100       mLoggable = new LoggableImpl(this, messageInfo);
85100    }
86  
87     /**
88      * Constructor getting an log message info and a root exception.
89      *
90      * @param messageInfo the log message info for this exception
91      * @param cause the problem that caused this exception to be thrown
92      */
93     protected BaseException (LogMessageInfo messageInfo, Throwable cause)
94     {
95100       super(messageInfo.getSymbol(), cause);
96100       mLoggable = new LoggableImpl(this, messageInfo, cause);
97100    }
98  
99     /** {@inheritDoc} */
100     public Throwable initCause (Throwable cause)
101     {
1020       super.initCause(cause);
1030       mLoggable.initCause(cause);
1040       return this;
105     }
106  
107     /** {@inheritDoc} */
108     public final void addParameter (String name, Serializable value)
109     {
110100       mLoggable.addParameter(name, value);
111100    }
112  
113     /** {@inheritDoc} */
114     public String getInstanceId ()
115     {
116100       return mLoggable.getInstanceId();
117     }
118  
119     /** {@inheritDoc} */
120     public final String getMessage ()
121     {
122100       return mLoggable.getMessage();
123     }
124  
125     /** {@inheritDoc} */
126     public final void log ()
127     {
128100       mLoggable.log();
129100    }
130  
131     /** {@inheritDoc} */
132     public Throwable getCause ()
133     {
134100       return mLoggable.getCause();
135     }
136  
137     /** {@inheritDoc} */
138     public long getEventTime ()
139     {
140100       return mLoggable.getEventTime();
141     }
142  
143     /** {@inheritDoc} */
144     public LogMessageInfo getLogMessageInfo ()
145     {
146100       return mLoggable.getLogMessageInfo();
147     }
148  
149     /** {@inheritDoc} */
150     public String getNodeId ()
151     {
152100       return mLoggable.getNodeId();
153     }
154  
155     /** {@inheritDoc} */
156     public List getParameter (String name)
157     {
158100       return mLoggable.getParameter(name);
159     }
160  
161     /** {@inheritDoc} */
162     public Set getParameterNames ()
163     {
164100       return mLoggable.getParameterNames();
165     }
166  
167     /** {@inheritDoc} */
168     public long getThreadId ()
169     {
170100       return mLoggable.getThreadId();
171     }
172  
173     /** {@inheritDoc} */
174     public String getTrackingNumber ()
175     {
176100       return mLoggable.getTrackingNumber();
177     }
178  
179     /** {@inheritDoc} */
180     public String getSourceClass ()
181     {
1820       return mLoggable.getSourceClass();
183     }
184  
185     /** {@inheritDoc} */
186     public String getSourceMethod ()
187     {
1880       return mLoggable.getSourceMethod();
189     }
190  
191     /** {@inheritDoc} */
192     public String getThreadName ()
193     {
194100        return mLoggable.getThreadName();
195     }
196  
197     /** {@inheritDoc} */
198     public String toString ()
199     {
200100       return mLoggable.toString();
201     }
202  
203     /** {@inheritDoc} */
204     public String toDetailedString ()
205     {
2060       return mLoggable.toDetailedString();
207     }
208  
209     protected final void logCreation ()
210     {
2110        if (LOGGER.isLoggable(
212             RteLogMessage.ExceptionCreated.LOG_LEVEL))
213         {
2140            final LogEvent logEvent
215                 = new LogEvent(RteLogMessage.EXCEPTION_CREATED, this);
2160            RteLogMessage.ExceptionCreated.addParameters(
217                 logEvent, mLoggable.getLogMessageInfo().getSymbol(),
218                 mLoggable.getMessage());
2190            LOGGER.logp(logEvent.getLogMessageInfo().getLogLevel(),
220                 logEvent.getSourceClass(), logEvent.getSourceMethod(),
221                 logEvent.getMessage(), logEvent);
222         }
2230    }
224  
225     LoggableImpl getExceptionImpl ()
226     {
2270       return mLoggable;
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.BaseRuntimeException:92 Delegation code can not be externalized further.