• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mybatis / ibatis-2 / 692

27 Dec 2025 03:18AM UTC coverage: 65.607% (+0.04%) from 65.57%
692

push

github

web-flow
Merge pull request #329 from hazendaz/master

Various cleanup

1602 of 2802 branches covered (57.17%)

70 of 95 new or added lines in 30 files covered. (73.68%)

6 existing lines in 5 files now uncovered.

5057 of 7708 relevant lines covered (65.61%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.38
/src/main/java/com/ibatis/common/beans/GenericProbe.java
1
/*
2
 * Copyright 2004-2025 the original author or authors.
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
 *    https://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
package com.ibatis.common.beans;
17

18
import java.util.List;
19
import java.util.Map;
20
import java.util.StringTokenizer;
21

22
/**
23
 * StaticBeanProbe provides methods that allow simple, reflective access to JavaBeans style properties. Methods are
24
 * provided for all simple types as well as object types.
25
 * <p>
26
 * Examples:
27
 * <p>
28
 * StaticBeanProbe.setObject(object, propertyName, value);
29
 * <P>
30
 * Object value = StaticBeanProbe.getObject(object, propertyName);
31
 */
32
public class GenericProbe extends BaseProbe {
33

34
  /** The Constant BEAN_PROBE. */
35
  private static final BaseProbe BEAN_PROBE = new ComplexBeanProbe();
1✔
36

37
  /** The Constant DOM_PROBE. */
38
  private static final BaseProbe DOM_PROBE = new DomProbe();
1✔
39

40
  /**
41
   * Instantiates a new generic probe.
42
   */
43
  protected GenericProbe() {
1✔
44
  }
1✔
45

46
  /**
47
   * Gets an object from a Map or bean
48
   *
49
   * @param object
50
   *          - the object to probe
51
   * @param name
52
   *          - the name of the property (or map entry)
53
   *
54
   * @return The value of the property (or map entry)
55
   *
56
   * @see com.ibatis.common.beans.BaseProbe#getObject(java.lang.Object, java.lang.String)
57
   */
58
  @Override
59
  public Object getObject(Object object, String name) {
60

61
    if (object instanceof org.w3c.dom.Document) {
1!
62
      return DOM_PROBE.getObject(object, name);
×
63
    } else if (object instanceof List) {
1✔
64
      return BEAN_PROBE.getIndexedProperty(object, name);
1✔
65
    } else if (object instanceof Object[]) {
1!
66
      return BEAN_PROBE.getIndexedProperty(object, name);
×
67
    } else if (object instanceof char[]) {
1!
68
      return BEAN_PROBE.getIndexedProperty(object, name);
×
69
    } else if (object instanceof boolean[]) {
1!
70
      return BEAN_PROBE.getIndexedProperty(object, name);
×
71
    } else if (object instanceof byte[]) {
1!
72
      return BEAN_PROBE.getIndexedProperty(object, name);
×
73
    } else if (object instanceof double[]) {
1!
74
      return BEAN_PROBE.getIndexedProperty(object, name);
×
75
    } else if (object instanceof float[]) {
1!
76
      return BEAN_PROBE.getIndexedProperty(object, name);
×
77
    } else if (object instanceof int[]) {
1!
78
      return BEAN_PROBE.getIndexedProperty(object, name);
×
79
    } else if (object instanceof long[]) {
1!
80
      return BEAN_PROBE.getIndexedProperty(object, name);
×
81
    } else if (object instanceof short[]) {
1!
82
      return BEAN_PROBE.getIndexedProperty(object, name);
×
83
    } else {
84
      return BEAN_PROBE.getObject(object, name);
1✔
85
    }
86
  }
87

88
  /**
89
   * Sets an object in a Map or bean
90
   *
91
   * @param object
92
   *          - the object to probe
93
   * @param name
94
   *          - the name of the property (or map entry)
95
   * @param value
96
   *          - the new value of the property (or map entry)
97
   *
98
   * @see com.ibatis.common.beans.BaseProbe#setObject(java.lang.Object, java.lang.String, java.lang.Object)
99
   */
100
  @Override
101
  public void setObject(Object object, String name, Object value) {
102
    if (object instanceof org.w3c.dom.Document) {
1!
103
      DOM_PROBE.setObject(object, name, value);
×
104
    } else {
105
      BEAN_PROBE.setObject(object, name, value);
1✔
106
    }
107
  }
1✔
108

109
  /**
110
   * Gets an array of the readable properties in a Map or JavaBean
111
   *
112
   * @param object
113
   *          - the object to get properties for
114
   *
115
   * @return The array of properties (or map entries)
116
   *
117
   * @see com.ibatis.common.beans.BaseProbe#getReadablePropertyNames(java.lang.Object)
118
   */
119
  @Override
120
  public String[] getReadablePropertyNames(Object object) {
121
    if (object instanceof org.w3c.dom.Document) {
×
122
      return DOM_PROBE.getReadablePropertyNames(object);
×
123
    }
NEW
124
    return BEAN_PROBE.getReadablePropertyNames(object);
×
125
  }
126

127
  /**
128
   * Gets an array of the writeable properties in a Map or JavaBean
129
   *
130
   * @param object
131
   *          - the object to get properties for
132
   *
133
   * @return The array of properties (or map entries)
134
   *
135
   * @see com.ibatis.common.beans.BaseProbe#getWriteablePropertyNames(java.lang.Object)
136
   */
137
  @Override
138
  public String[] getWriteablePropertyNames(Object object) {
139
    if (object instanceof org.w3c.dom.Document) {
×
140
      return DOM_PROBE.getWriteablePropertyNames(object);
×
141
    }
NEW
142
    return BEAN_PROBE.getWriteablePropertyNames(object);
×
143
  }
144

145
  /**
146
   * Returns the class that the setter expects to receive as a parameter when setting a property value.
147
   *
148
   * @param object
149
   *          - The class to check
150
   * @param name
151
   *          - the name of the property
152
   *
153
   * @return The type of the property
154
   *
155
   * @see com.ibatis.common.beans.Probe#getPropertyTypeForSetter(java.lang.Object, java.lang.String)
156
   */
157
  @Override
158
  public Class getPropertyTypeForSetter(Object object, String name) {
159
    if (object instanceof Class) {
1✔
160
      return getClassPropertyTypeForSetter((Class) object, name);
1✔
161
    }
162
    if (object instanceof org.w3c.dom.Document) {
1!
UNCOV
163
      return DOM_PROBE.getPropertyTypeForSetter(object, name);
×
164
    } else {
165
      return BEAN_PROBE.getPropertyTypeForSetter(object, name);
1✔
166
    }
167
  }
168

169
  /**
170
   * Returns the class that the getter will return when reading a property value.
171
   *
172
   * @param object
173
   *          The bean to check
174
   * @param name
175
   *          The name of the property
176
   *
177
   * @return The type of the property
178
   *
179
   * @see com.ibatis.common.beans.Probe#getPropertyTypeForGetter(java.lang.Object, java.lang.String)
180
   */
181
  @Override
182
  public Class getPropertyTypeForGetter(Object object, String name) {
183
    if (object instanceof Class) {
1✔
184
      return getClassPropertyTypeForGetter((Class) object, name);
1✔
185
    }
186
    if (object instanceof org.w3c.dom.Document) {
1!
UNCOV
187
      return DOM_PROBE.getPropertyTypeForGetter(object, name);
×
188
    } else if (name.indexOf('[') > -1) {
1✔
189
      return BEAN_PROBE.getIndexedType(object, name);
1✔
190
    } else {
191
      return BEAN_PROBE.getPropertyTypeForGetter(object, name);
1✔
192
    }
193
  }
194

195
  /**
196
   * Checks to see if an object has a writable property by a given name
197
   *
198
   * @param object
199
   *          The bean to check
200
   * @param propertyName
201
   *          The property to check for
202
   *
203
   * @return True if the property exists and is writable
204
   *
205
   * @see com.ibatis.common.beans.Probe#hasWritableProperty(java.lang.Object, java.lang.String)
206
   */
207
  @Override
208
  public boolean hasWritableProperty(Object object, String propertyName) {
209
    if (object instanceof org.w3c.dom.Document) {
×
210
      return DOM_PROBE.hasWritableProperty(object, propertyName);
×
211
    }
NEW
212
    return BEAN_PROBE.hasWritableProperty(object, propertyName);
×
213
  }
214

215
  /**
216
   * Checks to see if a bean has a readable property by a given name
217
   *
218
   * @param object
219
   *          The bean to check
220
   * @param propertyName
221
   *          The property to check for
222
   *
223
   * @return True if the property exists and is readable
224
   *
225
   * @see com.ibatis.common.beans.Probe#hasReadableProperty(java.lang.Object, java.lang.String)
226
   */
227
  @Override
228
  public boolean hasReadableProperty(Object object, String propertyName) {
229
    if (object instanceof org.w3c.dom.Document) {
1!
230
      return DOM_PROBE.hasReadableProperty(object, propertyName);
×
231
    }
232
    return BEAN_PROBE.hasReadableProperty(object, propertyName);
1✔
233
  }
234

235
  @Override
236
  protected void setProperty(Object object, String property, Object value) {
237
    if (object instanceof org.w3c.dom.Document) {
×
238
      DOM_PROBE.setProperty(object, property, value);
×
239
    } else {
240
      BEAN_PROBE.setProperty(object, property, value);
×
241
    }
242
  }
×
243

244
  @Override
245
  protected Object getProperty(Object object, String property) {
246
    if (object instanceof org.w3c.dom.Document) {
×
247
      return DOM_PROBE.getProperty(object, property);
×
248
    }
NEW
249
    return BEAN_PROBE.getProperty(object, property);
×
250
  }
251

252
  /**
253
   * Gets the class property type for getter.
254
   *
255
   * @param type
256
   *          the type
257
   * @param name
258
   *          the name
259
   *
260
   * @return the class property type for getter
261
   */
262
  private Class getClassPropertyTypeForGetter(Class type, String name) {
263

264
    if (name.indexOf('.') > -1) {
1!
265
      StringTokenizer parser = new StringTokenizer(name, ".");
×
266
      while (parser.hasMoreTokens()) {
×
267
        name = parser.nextToken();
×
268
        if (Map.class.isAssignableFrom(type)) {
×
269
          type = Object.class;
×
270
          break;
×
271
        }
272
        type = ClassInfo.getInstance(type).getGetterType(name);
×
273
      }
274
    } else {
×
275
      type = ClassInfo.getInstance(type).getGetterType(name);
1✔
276
    }
277

278
    return type;
1✔
279
  }
280

281
  /**
282
   * Returns the class that the setter expects to receive as a parameter when setting a property value.
283
   *
284
   * @param type
285
   *          The class to check
286
   * @param name
287
   *          The name of the property
288
   *
289
   * @return The type of the property
290
   */
291
  private Class getClassPropertyTypeForSetter(Class type, String name) {
292

293
    if (name.indexOf('.') > -1) {
1✔
294
      StringTokenizer parser = new StringTokenizer(name, ".");
1✔
295
      while (parser.hasMoreTokens()) {
1✔
296
        name = parser.nextToken();
1✔
297
        if (Map.class.isAssignableFrom(type)) {
1!
298
          type = Object.class;
×
299
          break;
×
300
        }
301
        type = ClassInfo.getInstance(type).getSetterType(name);
1✔
302
      }
303
    } else {
1✔
304
      type = ClassInfo.getInstance(type).getSetterType(name);
1✔
305
    }
306

307
    return type;
1✔
308
  }
309

310
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc