001: package org.drools.base.extractors;
002:
003: import java.lang.reflect.Method;
004:
005: import org.drools.RuntimeDroolsException;
006: import org.drools.base.BaseClassFieldExtractor;
007: import org.drools.base.ValueType;
008: import org.drools.common.InternalWorkingMemory;
009:
010: public abstract class BaseShortClassFieldExtractor extends
011: BaseClassFieldExtractor {
012:
013: private static final long serialVersionUID = 400L;
014:
015: public BaseShortClassFieldExtractor(final Class clazz,
016: final String fieldName) {
017: super (clazz, fieldName);
018: }
019:
020: /**
021: * This constructor is not supposed to be used from outside the class hirarchy
022: *
023: * @param index
024: * @param fieldType
025: * @param valueType
026: */
027: protected BaseShortClassFieldExtractor(final int index,
028: final Class fieldType, final ValueType valueType) {
029: super (index, fieldType, valueType);
030: }
031:
032: public Object getValue(InternalWorkingMemory workingMemory,
033: final Object object) {
034: return new Long(getShortValue(workingMemory, object));
035: }
036:
037: public boolean getBooleanValue(InternalWorkingMemory workingMemory,
038: final Object object) {
039: throw new RuntimeDroolsException(
040: "Conversion to boolean not supported from short");
041: }
042:
043: public byte getByteValue(InternalWorkingMemory workingMemory,
044: final Object object) {
045: return (byte) getShortValue(workingMemory, object);
046:
047: }
048:
049: public char getCharValue(InternalWorkingMemory workingMemory,
050: final Object object) {
051: throw new RuntimeDroolsException(
052: "Conversion to char not supported from short");
053: }
054:
055: public double getDoubleValue(InternalWorkingMemory workingMemory,
056: final Object object) {
057: return getShortValue(workingMemory, object);
058: }
059:
060: public float getFloatValue(InternalWorkingMemory workingMemory,
061: final Object object) {
062: return getShortValue(workingMemory, object);
063: }
064:
065: public int getIntValue(InternalWorkingMemory workingMemory,
066: final Object object) {
067: return getShortValue(workingMemory, object);
068: }
069:
070: public long getLongValue(InternalWorkingMemory workingMemory,
071: final Object object) {
072: return getShortValue(workingMemory, object);
073: }
074:
075: public abstract short getShortValue(
076: InternalWorkingMemory workingMemory, Object object);
077:
078: public boolean isNullValue(InternalWorkingMemory workingMemory,
079: final Object object) {
080: return false;
081: }
082:
083: public Method getNativeReadMethod() {
084: try {
085: return this .getClass().getDeclaredMethod(
086: "getShortValue",
087: new Class[] { InternalWorkingMemory.class,
088: Object.class });
089: } catch (final Exception e) {
090: throw new RuntimeDroolsException(
091: "This is a bug. Please report to development team: "
092: + e.getMessage(), e);
093: }
094: }
095:
096: public int getHashCode(InternalWorkingMemory workingMemory,
097: final Object object) {
098: return getShortValue(workingMemory, object);
099: }
100: }
|