|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
AttributePathException.java | - | 0% | 0% | 0% |
|
1 | /* | |
2 | * Copyright (c) 2001-2004, | |
3 | * RedVerst Group, ISP RAS http://www.ispras.ru | |
4 | * 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 met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright notice, this | |
10 | * list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright notice, | |
13 | * this list of conditions and the following disclaimer in the documentation | |
14 | * and/or other materials provided with the distribution. | |
15 | * | |
16 | * 3. The names "ATP", "TreeDL", "RedVerst", "ISP RAS" | |
17 | * may not be used to endorse or promote products derived from this software | |
18 | * without specific prior written permission. | |
19 | * | |
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | |
24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | ||
32 | package com.unitesk.atp.dynattrs; | |
33 | ||
34 | /** | |
35 | * This exception reports about various problems while getting attribute value by attribute path: | |
36 | * syntax errors in attribute path, wrong attribute names etc. | |
37 | * Exception provides information about object and attribute. | |
38 | * A cause of exception contains additional information. | |
39 | * | |
40 | * @see Accessor#getAttribute( Object,String,Attributed) | |
41 | * | |
42 | * @author <A href="mailto:demakov@ispras.ru">Alexey Demakov</A> | |
43 | * @version $Id: AttributePathException.java,v 1.2 2004/10/11 15:00:41 all-x Exp $ | |
44 | */ | |
45 | public class AttributePathException extends RuntimeException | |
46 | { | |
47 | /** | |
48 | * No closing bracket for open bracket at position {@link #pos}. | |
49 | * The cause is null. | |
50 | */ | |
51 | public static final int NO_CLOSING_BRACKET = 1; | |
52 | ||
53 | /** | |
54 | * Problem with index value - it is not integer. | |
55 | * The cause is {@link ClassCastException} (index variable has not {@link Integer} value) | |
56 | * or {@link NumberFormatException} (index expression is not valid integer). | |
57 | */ | |
58 | public static final int INDEX_VALUE = 2; | |
59 | ||
60 | /** | |
61 | * Various problems with attributes. Wrong name etc. | |
62 | * Position of attribute name is in {@link #pos}, the cause is underlying | |
63 | * {@link AttributeException}. | |
64 | * Note that index variables are attributes of variableMap, so they also can be causes of | |
65 | * {@link AttributeException}. | |
66 | */ | |
67 | public static final int ATTRIBUTED_EXCEPTION = 3; | |
68 | ||
69 | /** | |
70 | * Creates an exception with the specified parameters. | |
71 | * | |
72 | * @param kind Error kind one of {link #NO_CLOSING_BRACKET}, {link #INDEX_VALUE}, | |
73 | * {link #ATTRIBUTED_EXCEPTION}. | |
74 | * @param obj Attributed object. | |
75 | * @param path Attribute path. | |
76 | * @param pos Error position (starting from 0). | |
77 | * @param cause Cause of this exception. | |
78 | */ | |
79 | 0 | public AttributePathException( int kind, Object obj, String path, int pos, Throwable cause ) |
80 | { | |
81 | 0 | super( cause ); |
82 | 0 | this.kind = kind; |
83 | 0 | this.obj = obj; |
84 | 0 | this.path = path; |
85 | 0 | this.pos = pos; |
86 | } | |
87 | ||
88 | 0 | public String getMessage() |
89 | { | |
90 | 0 | return "kind: " + getKindString() |
91 | + " object: '" + obj | |
92 | + "' path: '" + path | |
93 | + "' pos: '" + pos | |
94 | + "' cause: '" + getCause() + "'"; | |
95 | } | |
96 | ||
97 | /** | |
98 | * @return Error kind. | |
99 | */ | |
100 | 0 | public int getKind() |
101 | { | |
102 | 0 | return kind; |
103 | } | |
104 | ||
105 | 0 | public String getKindString() |
106 | { | |
107 | 0 | switch( kind ) |
108 | { | |
109 | 0 | case NO_CLOSING_BRACKET: |
110 | 0 | return "no closing bracket"; |
111 | 0 | case INDEX_VALUE: |
112 | 0 | return "wrong index value"; |
113 | 0 | case ATTRIBUTED_EXCEPTION: |
114 | 0 | return "bad attribute"; |
115 | 0 | default: |
116 | 0 | return "undocumented (error #" + kind + ")"; |
117 | } | |
118 | } | |
119 | ||
120 | /** | |
121 | * @return Attributed object. | |
122 | */ | |
123 | 0 | public Object getObject() |
124 | { | |
125 | 0 | return obj; |
126 | } | |
127 | ||
128 | /** | |
129 | * @return Attribute path. | |
130 | */ | |
131 | 0 | public String getPath() |
132 | { | |
133 | 0 | return path; |
134 | } | |
135 | ||
136 | /** | |
137 | * @return Error position in path. | |
138 | */ | |
139 | 0 | public int getPos() |
140 | { | |
141 | 0 | return pos; |
142 | } | |
143 | ||
144 | protected int kind; | |
145 | protected Object obj; | |
146 | protected String path; | |
147 | protected int pos; | |
148 | } |
|