@@ -50,101 +50,101 @@ ModelType getType() {
50
50
}
51
51
52
52
long asLong () {
53
- throw new IllegalArgumentException ();
53
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "long" , ModelType . LONG ) );
54
54
}
55
55
56
56
long asLong (final long defVal ) {
57
- throw new IllegalArgumentException ();
57
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "long" , ModelType . LONG ) );
58
58
}
59
59
60
60
int asInt () {
61
- throw new IllegalArgumentException ();
61
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "int" , ModelType . INT ) );
62
62
}
63
63
64
64
int asInt (final int defVal ) {
65
- throw new IllegalArgumentException ();
65
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "int" , ModelType . INT ) );
66
66
}
67
67
68
68
boolean asBoolean () {
69
- throw new IllegalArgumentException ();
69
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "boolean" , ModelType . BOOLEAN ) );
70
70
}
71
71
72
72
boolean asBoolean (final boolean defVal ) {
73
- throw new IllegalArgumentException ();
73
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "boolean" , ModelType . BOOLEAN ) );
74
74
}
75
75
76
76
double asDouble () {
77
- throw new IllegalArgumentException ();
77
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "double" , ModelType . DOUBLE ) );
78
78
}
79
79
80
80
double asDouble (final double defVal ) {
81
- throw new IllegalArgumentException ();
81
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "double" , ModelType . DOUBLE ) );
82
82
}
83
83
84
84
byte [] asBytes () {
85
- throw new IllegalArgumentException ();
85
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "byte[]" , ModelType . BYTES ) );
86
86
}
87
87
88
88
BigDecimal asBigDecimal () {
89
- throw new IllegalArgumentException ();
89
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "BigDecimal" , ModelType . BIG_DECIMAL ) );
90
90
}
91
91
92
92
BigInteger asBigInteger () {
93
- throw new IllegalArgumentException ();
93
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "BigInteger" , ModelType . BIG_INTEGER ) );
94
94
}
95
95
96
96
abstract String asString ();
97
97
98
98
Property asProperty () {
99
- throw new IllegalArgumentException ();
99
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "Property" , ModelType . PROPERTY ) );
100
100
}
101
101
102
102
List <Property > asPropertyList () {
103
- throw new IllegalArgumentException ();
103
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "List<Property>" , ModelType . OBJECT ) );
104
104
}
105
105
106
106
ValueExpression asExpression () {
107
- throw new IllegalArgumentException ();
107
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "ValueExpression" , ModelType . EXPRESSION ) );
108
108
}
109
109
110
110
ModelNode asObject () {
111
- throw new IllegalArgumentException ();
111
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "OBJECT" , ModelType . OBJECT ) );
112
112
}
113
113
114
114
ModelNode getChild (final String name ) {
115
- throw new IllegalArgumentException ();
115
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "OBJECT" , ModelType . OBJECT ) );
116
116
}
117
117
118
118
ModelNode removeChild (final String name ) {
119
- throw new IllegalArgumentException ();
119
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "OBJECT" , ModelType . OBJECT ) );
120
120
}
121
121
122
122
ModelNode removeChild (final int index ) {
123
123
throw new IllegalArgumentException ();
124
124
}
125
125
126
126
ModelNode getChild (final int index ) {
127
- throw new IllegalArgumentException ();
127
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "OBJECT" , ModelType . OBJECT ) );
128
128
}
129
129
130
130
ModelNode addChild () {
131
- throw new IllegalArgumentException ();
131
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "OBJECT" , ModelType . OBJECT ) );
132
132
}
133
133
134
134
ModelNode insertChild (int index ) {
135
135
throw new IllegalArgumentException ();
136
136
}
137
137
138
138
Set <String > getKeys () {
139
- throw new IllegalArgumentException ();
139
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "OBJECT" , ModelType . OBJECT ) );
140
140
}
141
141
142
142
List <ModelNode > asList () {
143
- throw new IllegalArgumentException ();
143
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "List<ModelNode>" , ModelType . LIST ) );
144
144
}
145
145
146
146
ModelType asType () {
147
- throw new IllegalArgumentException ();
147
+ throw new IllegalArgumentException (getNonConversionMessageWithSuggestion ( "ModelType" , ModelType . OBJECT ) );
148
148
}
149
149
150
150
ModelValue protect () {
@@ -390,4 +390,17 @@ ModelNode requireChild(final String name) throws NoSuchElementException {
390
390
ModelNode requireChild (final int index ) throws NoSuchElementException {
391
391
throw new NoSuchElementException ("No child exists at index [" + index + "]" );
392
392
}
393
+
394
+ private String getNonConversionMessageWithSuggestion (String desiredConversion , ModelType suggestedType ) {
395
+ String suggestion = suggestedType .name ();
396
+ if (suggestedType == ModelType .LIST ) {
397
+ suggestion = '[' + suggestion + ']' ;
398
+ } else if (suggestedType == ModelType .OBJECT ) {
399
+ suggestion = '{' + suggestion + '}' ;
400
+ }
401
+
402
+ // TODO i18n
403
+ return "Cannot convert a node of type " + getType () + " to " + desiredConversion +
404
+ ". Recommended type for this conversion is " + suggestion ;
405
+ }
393
406
}
0 commit comments