1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 public AttributePathException( int kind, Object obj, String path, int pos, Throwable cause )
80 {
81 super( cause );
82 this.kind = kind;
83 this.obj = obj;
84 this.path = path;
85 this.pos = pos;
86 }
87
88 public String getMessage()
89 {
90 return "kind: " + getKindString()
91 + " object: '" + obj
92 + "' path: '" + path
93 + "' pos: '" + pos
94 + "' cause: '" + getCause() + "'";
95 }
96
97 /***
98 * @return Error kind.
99 */
100 public int getKind()
101 {
102 return kind;
103 }
104
105 public String getKindString()
106 {
107 switch( kind )
108 {
109 case NO_CLOSING_BRACKET:
110 return "no closing bracket";
111 case INDEX_VALUE:
112 return "wrong index value";
113 case ATTRIBUTED_EXCEPTION:
114 return "bad attribute";
115 default:
116 return "undocumented (error #" + kind + ")";
117 }
118 }
119
120 /***
121 * @return Attributed object.
122 */
123 public Object getObject()
124 {
125 return obj;
126 }
127
128 /***
129 * @return Attribute path.
130 */
131 public String getPath()
132 {
133 return path;
134 }
135
136 /***
137 * @return Error position in path.
138 */
139 public int getPos()
140 {
141 return pos;
142 }
143
144 protected int kind;
145 protected Object obj;
146 protected String path;
147 protected int pos;
148 }