コード例 #1
0
  public void testSchemaXMLWSchemaWithRestriction() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("order");
    InputStream schemaStream =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI);
    assertNotNull(schemaStream);
    String schemaText = ParserTool.linesToText(ParserTool.readFile(schemaStream));
    eventTypeMeta.setSchemaText(schemaText);
    config.addEventType("OrderEvent", eventTypeMeta);

    epService = EPServiceProviderManager.getProvider("TestSchemaXML", config);
    epService.initialize();
    updateListener = new SupportUpdateListener();

    String text = "select order_amount from OrderEvent";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(updateListener);

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<order>\n"
            + "<order_amount>202.1</order_amount>"
            + "</order>");
    EventBean theEvent = updateListener.getLastNewData()[0];
    assertEquals(Double.class, theEvent.get("order_amount").getClass());
    assertEquals(202.1d, theEvent.get("order_amount"));
    updateListener.reset();
  }
コード例 #2
0
  public void testSchemaXMLWSchemaWithAll() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("event-page-visit");
    String schemaUri =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResource(CLASSLOADER_SCHEMA_WITH_ALL_URI)
            .toString();
    eventTypeMeta.setSchemaResource(schemaUri);
    eventTypeMeta.addNamespacePrefix("ss", "samples:schemas:simpleSchemaWithAll");
    eventTypeMeta.addXPathProperty("url", "/ss:event-page-visit/ss:url", XPathConstants.STRING);
    config.addEventType("PageVisitEvent", eventTypeMeta);

    epService = EPServiceProviderManager.getProvider("TestSchemaXML", config);
    epService.initialize();
    updateListener = new SupportUpdateListener();

    // url='page4'
    String text = "select a.url as sesja from pattern [ every a=PageVisitEvent(url='page1') ]";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(updateListener);

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n"
            + "<url>page1</url>"
            + "</event-page-visit>");
    EventBean theEvent = updateListener.getLastNewData()[0];
    assertEquals("page1", theEvent.get("sesja"));
    updateListener.reset();

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n"
            + "<url>page2</url>"
            + "</event-page-visit>");
    assertFalse(updateListener.isInvoked());

    EventType type =
        epService.getEPAdministrator().createEPL("select * from PageVisitEvent").getEventType();
    EPAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor(
              "sessionId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor(
              "customerId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor("url", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("method", Node.class, null, false, false, false, false, true),
        },
        type.getPropertyDescriptors());
  }
コード例 #3
0
ファイル: BaseXMLEventType.java プロジェクト: arberzal/esper
 public boolean equals(Object otherObj) {
   if (!(otherObj instanceof BaseXMLEventType)) {
     return false;
   }
   BaseXMLEventType other = (BaseXMLEventType) otherObj;
   return (configurationEventTypeXMLDOM.equals(other.configurationEventTypeXMLDOM));
 }
  public void replaceXMLEventType(String xmlEventTypeName, ConfigurationEventTypeXMLDOM config)
      throws ConfigurationException {
    SchemaModel schemaModel = null;
    if (config.getSchemaResource() != null || config.getSchemaText() != null) {
      try {
        schemaModel =
            XSDSchemaMapper.loadAndMap(config.getSchemaResource(), config.getSchemaText(), 2);
      } catch (Exception ex) {
        throw new ConfigurationException(ex.getMessage(), ex);
      }
    }

    try {
      eventAdapterService.replaceXMLEventType(xmlEventTypeName, config, schemaModel);
    } catch (EventAdapterException e) {
      throw new ConfigurationException("Error updating XML event type: " + e.getMessage(), e);
    }
  }
  public void addEventType(String eventTypeName, ConfigurationEventTypeXMLDOM xmlDOMEventTypeDesc) {
    SchemaModel schemaModel = null;

    if ((xmlDOMEventTypeDesc.getSchemaResource() != null)
        || (xmlDOMEventTypeDesc.getSchemaText() != null)) {
      try {
        schemaModel =
            XSDSchemaMapper.loadAndMap(
                xmlDOMEventTypeDesc.getSchemaResource(), xmlDOMEventTypeDesc.getSchemaText(), 2);
      } catch (Exception ex) {
        throw new ConfigurationException(ex.getMessage(), ex);
      }
    }

    try {
      eventAdapterService.addXMLDOMType(eventTypeName, xmlDOMEventTypeDesc, schemaModel, false);
    } catch (EventAdapterException t) {
      throw new ConfigurationException(t.getMessage(), t);
    }
  }
コード例 #6
0
ファイル: BaseXMLEventType.java プロジェクト: arberzal/esper
  /**
   * 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);
      }
    }
  }
コード例 #7
0
 private ConfigurationEventTypeXMLDOM getConfigTestType(
     String additionalXPathProperty, boolean isUseXPathPropertyExpression) {
   ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
   eventTypeMeta.setRootElementName("simpleEvent");
   String schemaUri =
       TestSchemaXMLEvent.class.getClassLoader().getResource(CLASSLOADER_SCHEMA_URI).toString();
   eventTypeMeta.setSchemaResource(schemaUri);
   eventTypeMeta.addNamespacePrefix("ss", "samples:schemas:simpleSchema");
   eventTypeMeta.addXPathProperty(
       "customProp", "count(/ss:simpleEvent/ss:nested3/ss:nested4)", XPathConstants.NUMBER);
   eventTypeMeta.setXPathPropertyExpr(isUseXPathPropertyExpression);
   if (additionalXPathProperty != null) {
     eventTypeMeta.addXPathProperty(
         additionalXPathProperty,
         "count(/ss:simpleEvent/ss:nested3/ss:nested4)",
         XPathConstants.NUMBER);
   }
   return eventTypeMeta;
 }
コード例 #8
0
ファイル: BaseXMLEventType.java プロジェクト: arberzal/esper
 public int hashCode() {
   return configurationEventTypeXMLDOM.hashCode();
 }
コード例 #9
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);
  }