コード例 #1
0
  /**
   * Ctor.
   *
   * @param typeName is the event type name
   * @param eventType is the event type of the wrapped events
   * @param properties is the additional properties this wrapper adds
   * @param metadata event type metadata
   * @param eventAdapterService is the service for resolving unknown wrapped types
   */
  public WrapperEventType(
      EventTypeMetadata metadata,
      String typeName,
      int eventTypeId,
      EventType eventType,
      Map<String, Object> properties,
      EventAdapterService eventAdapterService) {
    checkForRepeatedPropertyNames(eventType, properties);

    this.metadata = metadata;
    this.underlyingEventType = eventType;
    EventTypeMetadata metadataMapType = EventTypeMetadata.createAnonymous(typeName);
    this.underlyingMapType =
        new MapEventType(
            metadataMapType, typeName, 0, eventAdapterService, properties, null, null, null);
    this.isNoMapProperties = properties.isEmpty();
    this.eventAdapterService = eventAdapterService;
    this.eventTypeId = eventTypeId;
    propertyGetterCache = new HashMap<String, EventPropertyGetter>();

    updatePropertySet();

    if (metadata.getTypeClass() == EventTypeMetadata.TypeClass.NAMED_WINDOW) {
      startTimestampPropertyName = eventType.getStartTimestampPropertyName();
      endTimestampPropertyName = eventType.getEndTimestampPropertyName();
      EventTypeUtility.validateTimestampProperties(
          this, startTimestampPropertyName, endTimestampPropertyName);
    }
  }
コード例 #2
0
ファイル: BaseXMLEventType.java プロジェクト: arberzal/esper
  /**
   * 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);
  }