Coverage report

| %line | %branch
--- | --- | ---

org.apache.commons.jelly.JellyException

34%

86%

1

     /*

2

      * Copyright 2002,2004 The Apache Software Foundation.

3

      *

4

      * Licensed under the Apache License, Version 2.0 (the "License");

5

      * you may not use this file except in compliance with the License.

6

      * You may obtain a copy of the License at

7

      *

8

      *      http://www.apache.org/licenses/LICENSE-2.0

9

      *

10

      * Unless required by applicable law or agreed to in writing, software

11

      * distributed under the License is distributed on an "AS IS" BASIS,

12

      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

13

      * See the License for the specific language governing permissions and

14

      * limitations under the License.

15

      */

16

17

     package org.apache.commons.jelly;

18

19

     import java.io.PrintStream;

20

     import java.io.PrintWriter;

21

22

     /**

23

      * <p><code>JellyException</code> is the root of all Jelly exceptions.</p>

24

      *

25

      * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>

26

      * @version $Revision: 155420 $

27

      */

28

29

     public class JellyException extends Exception implements LocationAware {

30

31

         /** the underlying cause of the exception */

32

         private Throwable cause;

33

34

         /** the Jelly file which caused the problem */

35

         private String fileName;

36

37

         /** the tag name which caused the problem */

38

         private String elementName;

39

40

         /** the line number in the script of the error */

41

481

         private int lineNumber = -1;

42

43

         /** the column number in the script of the error */

44

481

         private int columnNumber = -1;

45

46

0

         public JellyException() {

47

0

         }

48

49

         public JellyException(String message) {

50

403

             super(message);

51

403

         }

52

53

         public JellyException(String message, Throwable cause) {

54

78

             super(message);

55

78

             this.cause = cause;

56

78

         }

57

58

         public JellyException(Throwable cause) {

59

0

             super(cause.getLocalizedMessage());

60

0

             this.cause = cause;

61

0

         }

62

63

         public JellyException(Throwable cause, String fileName, String elementName, int columnNumber, <span class="keyword">int lineNumber) {

64

0

             this(cause.getLocalizedMessage(), cause, fileName, elementName, columnNumber, lineNumber);

65

0

         }

66

67

         public JellyException(String reason, Throwable cause, String fileName, String elementName, int columnNumber, <span class="keyword">int lineNumber) {

68

0

             super( (reason==null?cause.getClass().getName():reason) );

69

0

             this.cause = cause;

70

0

             this.fileName = fileName;

71

0

             this.elementName = elementName;

72

0

             this.columnNumber = columnNumber;

73

0

             this.lineNumber = lineNumber;

74

0

         }

75

76

         public JellyException(String reason, String fileName, String elementName, int columnNumber, <span class="keyword">int lineNumber) {

77

0

             super(reason);

78

0

             this.fileName = fileName;

79

0

             this.elementName = elementName;

80

0

             this.columnNumber = columnNumber;

81

0

             this.lineNumber = lineNumber;

82

0

         }

83

84

         public Throwable getCause() {

85

52

             return cause;

86

         }

87

88

89

         /**

90

          * @return the line number of the tag

91

          */

92

         public int getLineNumber() {

93

637

             return lineNumber;

94

         }

95

96

         /**

97

          * Sets the line number of the tag

98

          */

99

         public void setLineNumber(int lineNumber) {

100

338

             this.lineNumber = lineNumber;

101

338

         }

102

103

         /**

104

          * @return the column number of the tag

105

          */

106

         public int getColumnNumber() {

107

0

             return columnNumber;

108

         }

109

110

         /**

111

          * Sets the column number of the tag

112

          */

113

         public void setColumnNumber(int columnNumber) {

114

338

             this.columnNumber = columnNumber;

115

338

         }

116

117

         /**

118

          * @return the Jelly file which caused the problem

119

          */

120

         public String getFileName() {

121

637

             return fileName;

122

         }

123

124

         /**

125

          * Sets the Jelly file which caused the problem

126

          */

127

         public void setFileName(String fileName) {

128

338

             this.fileName = fileName;

129

338

         }

130

131

132

         /**

133

          * @return the element name which caused the problem

134

          */

135

         public String getElementName() {

136

637

             return elementName;

137

         }

138

139

         /**

140

          * Sets the element name which caused the problem

141

          */

142

         public void setElementName(String elementName) {

143

338

             this.elementName = elementName;

144

338

         }

145

146

147

         public String getMessage() {

148

78

             return fileName + ":" + lineNumber + ":" + columnNumber + ": <" + elementName + "> " + getReason();

149

         }

150

151

         public String getReason() {

152

78

             return super.getMessage();

153

         }

154

155

         // #### overload the printStackTrace methods...

156

         public void printStackTrace(PrintWriter s) {

157

0

             synchronized (s) {

158

0

                 super.printStackTrace(s);

159

0

                 if  (cause != null) {

160

0

                     s.println("Root cause");

161

0

                     cause.printStackTrace(s);

162

                 }

163

0

             }

164

0

         }

165

166

         public void printStackTrace(PrintStream s) {

167

0

             synchronized (s) {

168

0

                 super.printStackTrace(s);

169

0

                 if  (cause != null) {

170

0

                     s.println("Root cause");

171

0

                     cause.printStackTrace(s);

172

                 }

173

0

             }

174

0

         }

175

176

         public void printStackTrace() {

177

0

             super.printStackTrace();

178

0

             if (cause != null) {

179

0

                 System.out.println("Root cause");

180

0

                 cause.printStackTrace();

181

             }

182

0

         }

183

184

     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.