Exemplo n.º 1
0
  /**
   * Constructor.
   *
   * @param fastMethod is the method to use to retrieve a value from the object
   * @param index is tge index within the array to get the property from
   * @param eventAdapterService factory for event beans and event types
   */
  public ArrayFastPropertyGetter(
      FastMethod fastMethod, int index, EventAdapterService eventAdapterService) {
    super(eventAdapterService, fastMethod.getReturnType().getComponentType(), null);
    this.index = index;
    this.fastMethod = fastMethod;

    if (index < 0) {
      throw new IllegalArgumentException("Invalid negative index value");
    }
  }
 /**
  * Ctor.
  *
  * @param eventAdapterService for generating event beans
  * @param method the method to invoke
  * @param useMapType is true to indicate that Map-events are generated
  * @param eventType is the event type to use
  */
 public MethodPollingExecStrategy(
     EventAdapterService eventAdapterService,
     FastMethod method,
     boolean useMapType,
     EventType eventType) {
   this.eventAdapterService = eventAdapterService;
   this.method = method;
   this.isArray = method.getReturnType().isArray();
   this.useMapType = useMapType;
   this.eventType = eventType;
 }
Exemplo n.º 3
0
  public Object getValue(Object instance) {
    try {
      if (getter != null) {
        return getter.invoke(instance, new Object[] {});
      }

      return field.get(instance);
    } catch (Exception e) {
      // todo is it good?
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 4
0
  public void setValue(Object instance, Object newValue) {
    try {
      if (setter != null) {
        setter.invoke(instance, new Object[] {newValue});
        return;
      }

      field.set(instance, newValue);
    } catch (Exception e) {
      // todo impl is is good?
      throw new RuntimeException(e);
    }
  }
Exemplo n.º 5
0
 private Object getBeanPropInternal(Object object, int index) throws PropertyAccessException {
   try {
     Object value = fastMethod.invoke(object, null);
     if (Array.getLength(value) <= index) {
       return null;
     }
     return Array.get(value, index);
   } catch (ClassCastException e) {
     throw new PropertyAccessException("Mismatched getter instance to event bean type");
   } catch (InvocationTargetException e) {
     throw new PropertyAccessException(e);
   }
 }
  public List<EventBean> poll(Object[] lookupValues) {
    List<EventBean> rowResult = null;
    try {
      Object invocationResult = method.invoke(null, lookupValues);
      if (invocationResult != null) {
        if (isArray) {
          int length = Array.getLength(invocationResult);
          if (length > 0) {
            rowResult = new ArrayList<EventBean>();
            for (int i = 0; i < length; i++) {
              Object value = Array.get(invocationResult, i);
              if (value == null) {
                log.warn(
                    "Expected non-null return result from method '"
                        + method.getName()
                        + "', but received null value");
                continue;
              }

              EventBean theEvent;
              if (useMapType) {
                if (!(value instanceof Map)) {
                  log.warn(
                      "Expected Map-type return result from method '"
                          + method.getName()
                          + "', but received type '"
                          + value.getClass()
                          + "'");
                  continue;
                }
                Map mapValues = (Map) value;
                theEvent = eventAdapterService.adapterForTypedMap(mapValues, eventType);
              } else {
                theEvent = eventAdapterService.adapterForBean(value);
              }

              rowResult.add(theEvent);
            }
          }
        } else {
          rowResult = new LinkedList<EventBean>();

          EventBean theEvent;
          if (useMapType) {
            if (!(invocationResult instanceof Map)) {
              log.warn(
                  "Expected Map-type return result from method '"
                      + method.getName()
                      + "', but received type '"
                      + invocationResult.getClass()
                      + "'");
            } else {
              Map mapValues = (Map) invocationResult;
              theEvent = eventAdapterService.adapterForTypedMap(mapValues, eventType);
              rowResult.add(theEvent);
            }
          } else {
            theEvent = eventAdapterService.adapterForBean(invocationResult);
            rowResult.add(theEvent);
          }
        }
      }
    } catch (InvocationTargetException ex) {
      throw new EPException(
          "Method '"
              + method.getName()
              + "' of class '"
              + method.getJavaMethod().getDeclaringClass().getName()
              + "' reported an exception: "
              + ex.getTargetException(),
          ex.getTargetException());
    }

    return rowResult;
  }
Exemplo n.º 7
0
 public String toString() {
   return "ArrayFastPropertyGetter " + " fastMethod=" + fastMethod.toString() + " index=" + index;
 }
 protected void handleSignalInternal(EPDataFlowSignal signal) throws InvocationTargetException {
   fastMethod.invoke(target, new Object[] {signal});
 }