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 BaseLongClassFieldExtractors extends
011: BaseClassFieldExtractor {
012:
013: private static final long serialVersionUID = 400L;
014:
015: public BaseLongClassFieldExtractors(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 BaseLongClassFieldExtractors(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(getLongValue(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 long");
041: }
042:
043: public byte getByteValue(InternalWorkingMemory workingMemory,
044: final Object object) {
045: return (byte) getLongValue(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 long");
053: }
054:
055: public double getDoubleValue(InternalWorkingMemory workingMemory,
056: final Object object) {
057: return getLongValue(workingMemory, object);
058: }
059:
060: public float getFloatValue(InternalWorkingMemory workingMemory,
061: final Object object) {
062: return getLongValue(workingMemory, object);
063: }
064:
065: public int getIntValue(InternalWorkingMemory workingMemory,
066: final Object object) {
067: return (int) getLongValue(workingMemory, object);
068: }
069:
070: public abstract long getLongValue(
071: InternalWorkingMemory workingMemory, Object object);
072:
073: public short getShortValue(InternalWorkingMemory workingMemory,
074: final Object object) {
075: return (short) getLongValue(workingMemory, object);
076: }
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: "getLongValue",
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: final long temp = getLongValue(workingMemory, object);
099: return (int) (temp ^ (temp >>> 32));
100: }
101:
102: }
|