Beispiel #1
0
  /**
   * Ctor.
   *
   * @param configurationEventTypeXMLDOM is the XML DOM configuration such as root element and
   *     schema names
   * @param metadata event type metadata
   * @param eventAdapterService for registration and lookup of types
   */
  public BaseXMLEventType(
      EventTypeMetadata metadata,
      int eventTypeId,
      ConfigurationEventTypeXMLDOM configurationEventTypeXMLDOM,
      EventAdapterService eventAdapterService) {
    super(eventAdapterService, metadata, eventTypeId, Node.class);
    this.rootElementName = configurationEventTypeXMLDOM.getRootElementName();
    this.configurationEventTypeXMLDOM = configurationEventTypeXMLDOM;
    xPathFactory = XPathFactory.newInstance();

    if (configurationEventTypeXMLDOM.getXPathFunctionResolver() != null) {
      try {
        XPathFunctionResolver fresolver =
            (XPathFunctionResolver)
                JavaClassHelper.instantiate(
                    XPathFunctionResolver.class,
                    configurationEventTypeXMLDOM.getXPathFunctionResolver());
        xPathFactory.setXPathFunctionResolver(fresolver);
      } catch (ClassInstantiationException ex) {
        throw new ConfigurationException(
            "Error configuring XPath function resolver for XML type '"
                + configurationEventTypeXMLDOM.getRootElementName()
                + "' : "
                + ex.getMessage(),
            ex);
      }
    }

    if (configurationEventTypeXMLDOM.getXPathVariableResolver() != null) {
      try {
        XPathVariableResolver vresolver =
            (XPathVariableResolver)
                JavaClassHelper.instantiate(
                    XPathVariableResolver.class,
                    configurationEventTypeXMLDOM.getXPathVariableResolver());
        xPathFactory.setXPathVariableResolver(vresolver);
      } catch (ClassInstantiationException ex) {
        throw new ConfigurationException(
            "Error configuring XPath variable resolver for XML type '"
                + configurationEventTypeXMLDOM.getRootElementName()
                + "' : "
                + ex.getMessage(),
            ex);
      }
    }
  }
Beispiel #2
0
  /**
   * Set the preconfigured event properties resolved by XPath expression.
   *
   * @param explicitXPathProperties are preconfigured event properties
   * @param additionalSchemaProperties the explicit properties
   */
  protected void initialize(
      Collection<ConfigurationEventTypeXMLDOM.XPathPropertyDesc> explicitXPathProperties,
      List<ExplicitPropertyDescriptor> additionalSchemaProperties) {
    // make sure we override those explicitly provided with those derived from a metadataz
    Map<String, ExplicitPropertyDescriptor> namedProperties =
        new LinkedHashMap<String, ExplicitPropertyDescriptor>();
    for (ExplicitPropertyDescriptor desc : additionalSchemaProperties) {
      namedProperties.put(desc.getDescriptor().getPropertyName(), desc);
    }

    String xpathExpression = null;
    try {

      for (ConfigurationEventTypeXMLDOM.XPathPropertyDesc property : explicitXPathProperties) {
        XPath xPath = xPathFactory.newXPath();
        if (namespaceContext != null) {
          xPath.setNamespaceContext(namespaceContext);
        }

        xpathExpression = property.getXpath();
        if (log.isInfoEnabled()) {
          log.info(
              "Compiling XPath expression for property '"
                  + property.getName()
                  + "' as '"
                  + xpathExpression
                  + "'");
        }
        XPathExpression expression = xPath.compile(xpathExpression);

        FragmentFactoryXPathPredefinedGetter fragmentFactory = null;
        boolean isFragment = false;
        if (property.getOptionaleventTypeName() != null) {
          fragmentFactory =
              new FragmentFactoryXPathPredefinedGetter(
                  this.getEventAdapterService(),
                  property.getOptionaleventTypeName(),
                  property.getName());
          isFragment = true;
        }
        boolean isArray = false;
        if (property.getType().equals(XPathConstants.NODESET)) {
          isArray = true;
        }

        EventPropertyGetter getter =
            new XPathPropertyGetter(
                property.getName(),
                xpathExpression,
                expression,
                property.getType(),
                property.getOptionalCastToType(),
                fragmentFactory);
        Class returnType =
            SchemaUtil.toReturnType(property.getType(), property.getOptionalCastToType());

        EventPropertyDescriptor desc =
            new EventPropertyDescriptor(
                property.getName(), returnType, null, false, false, isArray, false, isFragment);
        ExplicitPropertyDescriptor explicit =
            new ExplicitPropertyDescriptor(
                desc, getter, isArray, property.getOptionaleventTypeName());
        namedProperties.put(desc.getPropertyName(), explicit);
      }
    } catch (XPathExpressionException ex) {
      throw new EPException(
          "XPath expression could not be compiled for expression '" + xpathExpression + '\'', ex);
    }

    super.initialize(new ArrayList<ExplicitPropertyDescriptor>(namedProperties.values()));

    // evaluate start and end timestamp properties if any
    startTimestampPropertyName = configurationEventTypeXMLDOM.getStartTimestampPropertyName();
    endTimestampPropertyName = configurationEventTypeXMLDOM.getEndTimestampPropertyName();
    EventTypeUtility.validateTimestampProperties(
        this, startTimestampPropertyName, endTimestampPropertyName);
  }