01: package org.drools.base.extractors;
02:
03: import java.lang.reflect.Method;
04:
05: import org.drools.RuntimeDroolsException;
06: import org.drools.base.BaseClassFieldExtractor;
07: import org.drools.base.ValueType;
08: import org.drools.common.InternalWorkingMemory;
09:
10: public abstract class BaseCharClassFieldExtractor extends
11: BaseClassFieldExtractor {
12:
13: private static final long serialVersionUID = 400L;
14:
15: public BaseCharClassFieldExtractor(final Class clazz,
16: final String fieldName) {
17: super (clazz, fieldName);
18: }
19:
20: /**
21: * This constructor is not supposed to be used from outside the class hirarchy
22: *
23: * @param index
24: * @param fieldType
25: * @param valueType
26: */
27: protected BaseCharClassFieldExtractor(final int index,
28: final Class fieldType, final ValueType valueType) {
29: super (index, fieldType, valueType);
30: }
31:
32: public Object getValue(InternalWorkingMemory workingMemory,
33: final Object object) {
34: return new Character(getCharValue(workingMemory, object));
35: }
36:
37: public boolean getBooleanValue(InternalWorkingMemory workingMemory,
38: final Object object) {
39: throw new RuntimeDroolsException(
40: "Conversion to boolean not supported from char");
41: }
42:
43: public byte getByteValue(InternalWorkingMemory workingMemory,
44: final Object object) {
45: return (byte) getCharValue(workingMemory, object);
46: }
47:
48: public abstract char getCharValue(
49: InternalWorkingMemory workingMemory, Object object);
50:
51: public double getDoubleValue(InternalWorkingMemory workingMemory,
52: final Object object) {
53: return getCharValue(workingMemory, object);
54: }
55:
56: public float getFloatValue(InternalWorkingMemory workingMemory,
57: final Object object) {
58: return getCharValue(workingMemory, object);
59: }
60:
61: public int getIntValue(InternalWorkingMemory workingMemory,
62: final Object object) {
63: return getCharValue(workingMemory, object);
64: }
65:
66: public long getLongValue(InternalWorkingMemory workingMemory,
67: final Object object) {
68: return getCharValue(workingMemory, object);
69: }
70:
71: public short getShortValue(InternalWorkingMemory workingMemory,
72: final Object object) {
73: return (short) getCharValue(workingMemory, object);
74: }
75:
76: public boolean isNullValue(InternalWorkingMemory workingMemory,
77: final Object object) {
78: return false;
79: }
80:
81: public Method getNativeReadMethod() {
82: try {
83: return this .getClass().getDeclaredMethod(
84: "getCharValue",
85: new Class[] { InternalWorkingMemory.class,
86: Object.class });
87: } catch (final Exception e) {
88: throw new RuntimeDroolsException(
89: "This is a bug. Please report to development team: "
90: + e.getMessage(), e);
91: }
92: }
93:
94: public int getHashCode(InternalWorkingMemory workingMemory,
95: final Object object) {
96: return getCharValue(workingMemory, object);
97: }
98: }
|