/*
***************************************************************************************
* Copyright (C) 2006 EsperTech, Inc. All rights reserved. *
* http://www.espertech.com/esper *
* http://www.espertech.com *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license *
* a copy of which has been included with this distribution in the license.txt file. *
***************************************************************************************
*/
package com.espertech.esper.event.arr;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.PropertyAccessException;
import com.espertech.esper.event.BaseNestableEventUtil;
/**
* Getter for array events.
*/
public class ObjectArrayEventBeanArrayIndexedPropertyGetter implements ObjectArrayEventPropertyGetter {
private final int propertyIndex;
private final int index;
/**
* Ctor.
*
* @param propertyIndex property index
* @param index array index
*/
public ObjectArrayEventBeanArrayIndexedPropertyGetter(int propertyIndex, int index) {
this.propertyIndex = propertyIndex;
this.index = index;
}
public Object getObjectArray(Object[] array) throws PropertyAccessException {
// If the map does not contain the key, this is allowed and represented as null
EventBean[] wrapper = (EventBean[]) array[propertyIndex];
return BaseNestableEventUtil.getArrayPropertyUnderlying(wrapper, index);
}
public boolean isObjectArrayExistsProperty(Object[] array) {
return true;
}
public Object get(EventBean obj) {
Object[] array = BaseNestableEventUtil.checkedCastUnderlyingObjectArray(obj);
return getObjectArray(array);
}
public boolean isExistsProperty(EventBean eventBean) {
return true; // Property exists as the property is not dynamic (unchecked)
}
public Object getFragment(EventBean obj) {
Object[] array = BaseNestableEventUtil.checkedCastUnderlyingObjectArray(obj);
EventBean[] wrapper = (EventBean[]) array[propertyIndex];
return BaseNestableEventUtil.getArrayPropertyBean(wrapper, index);
}
}