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

mybatis / ibatis-2 / 730

28 Dec 2025 10:16PM UTC coverage: 65.615% (+0.5%) from 65.146%
730

push

github

web-flow
Update README.md

1602 of 2802 branches covered (57.17%)

5053 of 7701 relevant lines covered (65.61%)

0.66 hits per line

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

52.56
/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
    }
64
    if ((object instanceof List) || (object instanceof Object[]) || (object instanceof char[])
1!
65
        || (object instanceof boolean[])) {
66
      return BEAN_PROBE.getIndexedProperty(object, name);
1✔
67
    }
68
    if (object instanceof byte[]) {
1!
69
      return BEAN_PROBE.getIndexedProperty(object, name);
×
70
    }
71
    if (object instanceof double[]) {
1!
72
      return BEAN_PROBE.getIndexedProperty(object, name);
×
73
    }
74
    if (object instanceof float[]) {
1!
75
      return BEAN_PROBE.getIndexedProperty(object, name);
×
76
    }
77
    if (object instanceof int[]) {
1!
78
      return BEAN_PROBE.getIndexedProperty(object, name);
×
79
    }
80
    if (object instanceof long[]) {
1!
81
      return BEAN_PROBE.getIndexedProperty(object, name);
×
82
    }
83
    if (object instanceof short[]) {
1!
84
      return BEAN_PROBE.getIndexedProperty(object, name);
×
85
    }
86
    return BEAN_PROBE.getObject(object, name);
1✔
87
  }
88

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

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

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

146
  /**
147
   * Returns the class that the setter expects to receive as a parameter when setting a property value.
148
   *
149
   * @param object
150
   *          - The class to check
151
   * @param name
152
   *          - the name of the property
153
   *
154
   * @return The type of the property
155
   *
156
   * @see com.ibatis.common.beans.Probe#getPropertyTypeForSetter(java.lang.Object, java.lang.String)
157
   */
158
  @Override
159
  public Class getPropertyTypeForSetter(Object object, String name) {
160
    if (object instanceof Class) {
1✔
161
      return getClassPropertyTypeForSetter((Class) object, name);
1✔
162
    }
163
    if (object instanceof org.w3c.dom.Document) {
1!
164
      return DOM_PROBE.getPropertyTypeForSetter(object, name);
×
165
    }
166
    return BEAN_PROBE.getPropertyTypeForSetter(object, name);
1✔
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!
187
      return DOM_PROBE.getPropertyTypeForGetter(object, name);
×
188
    }
189
    if (name.indexOf('[') > -1) {
1✔
190
      return BEAN_PROBE.getIndexedType(object, name);
1✔
191
    }
192
    return BEAN_PROBE.getPropertyTypeForGetter(object, name);
1✔
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
    }
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
    }
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

© 2025 Coveralls, Inc