示例#1
0
 @Override
 public void removeEventDefinition(Object o) {
   if (eventBuilderConfiguration.isTraceEnabled()) {
     trace.info(
         "[Event-Builder] Notifying event definition removal "
             + o.toString()
             + " to event listeners");
   }
   for (BasicEventListener basicEventListener : basicEventListeners) {
     basicEventListener.onRemoveDefinition(o);
   }
   for (Wso2EventListener wso2EventListener : wso2EventListeners) {
     wso2EventListener.onRemoveDefinition(o);
   }
   if (eventBuilderConfiguration.isTraceEnabled()) {
     trace.info(
         "[Event-Builder] Successfully notified all registered listeners of removing \n"
             + o.toString());
   }
 }
示例#2
0
  private void sendEvent(Object obj) {
    if (obj instanceof OMElement) {
      OMElement eventOMElement = (OMElement) obj;
      if (eventBuilderConfiguration.isTraceEnabled()) {
        trace.info("[Event-Builder] Received event as OMElement.\n" + eventOMElement.toString());
      }

      OMNamespace omNamespace = null;
      if (this.xPathDefinition == null || this.xPathDefinition.isEmpty()) {
        omNamespace = eventOMElement.getNamespace();
      }
      List<Object> objList = new ArrayList<Object>();
      for (XPathData xpathData : attributeXpathList) {
        AXIOMXPath xpath = xpathData.getXpath();
        OMElement omElementResult = null;
        String type = xpathData.getType();
        try {
          if (omNamespace != null) {
            xpath.addNamespaces(eventOMElement);
          }
          omElementResult = (OMElement) xpath.selectSingleNode(eventOMElement);
          Class<?> beanClass = Class.forName(type);
          Object returnedObj = null;
          if (omElementResult != null) {
            returnedObj =
                BeanUtil.deserialize(
                    beanClass, omElementResult, reflectionBasedObjectSupplier, null);
          } else if (xpathData.getDefaultValue() != null) {
            if (!beanClass.equals(String.class)) {
              Class<?> stringClass = String.class;
              Method valueOfMethod = beanClass.getMethod("valueOf", stringClass);
              returnedObj = valueOfMethod.invoke(null, xpathData.getDefaultValue());
            } else {
              returnedObj = xpathData.getDefaultValue();
            }
            log.warn("Unable to parse XPath to retrieve required attribute. Sending defaults.");
          } else {
            log.warn(
                "Unable to parse XPath to retrieve required attribute. Skipping to next attribute.");
          }
          objList.add(returnedObj);
        } catch (JaxenException e) {
          throw new EventBuilderConfigurationException("Error parsing xpath for " + xpath, e);
        } catch (ClassNotFoundException e) {
          throw new EventBuilderConfigurationException(
              "Cannot find specified class for type " + type);
        } catch (AxisFault axisFault) {
          throw new EventBuilderConfigurationException(
              "Error deserializing OMElement " + omElementResult, axisFault);
        } catch (NoSuchMethodException e) {
          throw new EventBuilderConfigurationException(
              "Error trying to convert default value to specified target type.", e);
        } catch (InvocationTargetException e) {
          throw new EventBuilderConfigurationException(
              "Error trying to convert default value to specified target type.", e);
        } catch (IllegalAccessException e) {
          throw new EventBuilderConfigurationException(
              "Error trying to convert default value to specified target type.", e);
        }
      }
      Object[] objArray = objList.toArray(new Object[objList.size()]);
      if (!this.basicEventListeners.isEmpty()) {
        if (eventBuilderConfiguration.isTraceEnabled()) {
          trace.info(
              "[Event-Builder] Sending event object array "
                  + Arrays.toString(objArray)
                  + " to all registered basic event listeners");
        }
        for (BasicEventListener basicEventListener : basicEventListeners) {
          basicEventListener.onEvent(objArray);
        }
      }
      if (!this.wso2EventListeners.isEmpty()) {
        Event event =
            new Event(
                exportedStreamDefinition.getStreamId(),
                System.currentTimeMillis(),
                null,
                null,
                objArray);
        if (eventBuilderConfiguration.isTraceEnabled()) {
          trace.info(
              "[Event-Builder] Sending event "
                  + event.toString()
                  + " to all registered wso2 event listeners");
        }
        for (Wso2EventListener wso2EventListener : wso2EventListeners) {
          wso2EventListener.onEvent(event);
        }
      }
    }
  }