Beispiel #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);
    }
  }
  private static Class resolveClassForTypeName(String type) {
    boolean isArray = false;
    if (type != null && EventTypeUtility.isPropertyArray(type)) {
      isArray = true;
      type = EventTypeUtility.getPropertyRemoveArray(type);
    }

    if (type == null) {
      throw new ConfigurationException("A null value has been provided for the type");
    }
    Class clazz = JavaClassHelper.getClassForSimpleName(type);
    if (clazz == null) {
      throw new ConfigurationException("The type '" + type + "' is not a recognized type");
    }

    if (isArray) {
      clazz = Array.newInstance(clazz, 0).getClass();
    }
    return clazz;
  }
  /**
   * Initialize event adapter service for config snapshot.
   *
   * @param eventAdapterService is events adapter
   * @param configSnapshot is the config snapshot
   */
  protected static void init(
      EventAdapterService eventAdapterService, ConfigurationInformation configSnapshot) {
    // Extract legacy event type definitions for each event type name, if supplied.
    //
    // We supply this information as setup information to the event adapter service
    // to allow discovery of superclasses and interfaces during event type construction for bean
    // events,
    // such that superclasses and interfaces can use the legacy type definitions.
    Map<String, ConfigurationEventTypeLegacy> classLegacyInfo =
        new HashMap<String, ConfigurationEventTypeLegacy>();
    for (Map.Entry<String, String> entry : configSnapshot.getEventTypeNames().entrySet()) {
      String typeName = entry.getKey();
      String className = entry.getValue();
      ConfigurationEventTypeLegacy legacyDef = configSnapshot.getEventTypesLegacy().get(typeName);
      if (legacyDef != null) {
        classLegacyInfo.put(className, legacyDef);
      }
    }
    eventAdapterService.setClassLegacyConfigs(classLegacyInfo);
    eventAdapterService.setDefaultPropertyResolutionStyle(
        configSnapshot.getEngineDefaults().getEventMeta().getClassPropertyResolutionStyle());
    eventAdapterService.setDefaultAccessorStyle(
        configSnapshot.getEngineDefaults().getEventMeta().getDefaultAccessorStyle());

    for (String javaPackage : configSnapshot.getEventTypeAutoNamePackages()) {
      eventAdapterService.addAutoNamePackage(javaPackage);
    }

    // Add from the configuration the Java event class names
    Map<String, String> javaClassNames = configSnapshot.getEventTypeNames();
    for (Map.Entry<String, String> entry : javaClassNames.entrySet()) {
      // Add Java class
      try {
        String typeName = entry.getKey();
        eventAdapterService.addBeanType(typeName, entry.getValue(), false, true, true, true);
      } catch (EventAdapterException ex) {
        throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
      }
    }

    // Add from the configuration the XML DOM names and type def
    Map<String, ConfigurationEventTypeXMLDOM> xmlDOMNames = configSnapshot.getEventTypesXMLDOM();
    for (Map.Entry<String, ConfigurationEventTypeXMLDOM> entry : xmlDOMNames.entrySet()) {
      SchemaModel schemaModel = null;
      if ((entry.getValue().getSchemaResource() != null)
          || (entry.getValue().getSchemaText() != null)) {
        try {
          schemaModel =
              XSDSchemaMapper.loadAndMap(
                  entry.getValue().getSchemaResource(), entry.getValue().getSchemaText(), 2);
        } catch (Exception ex) {
          throw new ConfigurationException(ex.getMessage(), ex);
        }
      }

      // Add XML DOM type
      try {
        eventAdapterService.addXMLDOMType(entry.getKey(), entry.getValue(), schemaModel, true);
      } catch (EventAdapterException ex) {
        throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
      }
    }

    // Add maps in dependency order such that supertypes are added before subtypes
    Set<String> dependentMapOrder;
    try {
      Map<String, Set<String>> typesReferences =
          toTypesReferences(configSnapshot.getMapTypeConfigurations());
      dependentMapOrder = GraphUtil.getTopDownOrder(typesReferences);
    } catch (GraphCircularDependencyException e) {
      throw new ConfigurationException(
          "Error configuring engine, dependency graph between map type names is circular: "
              + e.getMessage(),
          e);
    }

    Map<String, Properties> mapNames = configSnapshot.getEventTypesMapEvents();
    Map<String, Map<String, Object>> nestableMapNames =
        configSnapshot.getEventTypesNestableMapEvents();
    dependentMapOrder.addAll(mapNames.keySet());
    dependentMapOrder.addAll(nestableMapNames.keySet());
    try {
      for (String mapName : dependentMapOrder) {
        ConfigurationEventTypeMap mapConfig =
            configSnapshot.getMapTypeConfigurations().get(mapName);
        Properties propertiesUnnested = mapNames.get(mapName);
        if (propertiesUnnested != null) {
          Map<String, Object> propertyTypes = createPropertyTypes(propertiesUnnested);
          Map<String, Object> propertyTypesCompiled =
              EventTypeUtility.compileMapTypeProperties(propertyTypes, eventAdapterService);
          eventAdapterService.addNestableMapType(
              mapName, propertyTypesCompiled, mapConfig, true, true, true, false, false);
        }

        Map<String, Object> propertiesNestable = nestableMapNames.get(mapName);
        if (propertiesNestable != null) {
          Map<String, Object> propertiesNestableCompiled =
              EventTypeUtility.compileMapTypeProperties(propertiesNestable, eventAdapterService);
          eventAdapterService.addNestableMapType(
              mapName, propertiesNestableCompiled, mapConfig, true, true, true, false, false);
        }
      }
    } catch (EventAdapterException ex) {
      throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
    }

    // Add object-array in dependency order such that supertypes are added before subtypes
    Set<String> dependentObjectArrayOrder;
    try {
      Map<String, Set<String>> typesReferences =
          toTypesReferences(configSnapshot.getObjectArrayTypeConfigurations());
      dependentObjectArrayOrder = GraphUtil.getTopDownOrder(typesReferences);
    } catch (GraphCircularDependencyException e) {
      throw new ConfigurationException(
          "Error configuring engine, dependency graph between object array type names is circular: "
              + e.getMessage(),
          e);
    }
    Map<String, Map<String, Object>> nestableObjectArrayNames =
        configSnapshot.getEventTypesNestableObjectArrayEvents();
    dependentObjectArrayOrder.addAll(nestableObjectArrayNames.keySet());
    try {
      for (String objectArrayName : dependentObjectArrayOrder) {
        ConfigurationEventTypeObjectArray objectArrayConfig =
            configSnapshot.getObjectArrayTypeConfigurations().get(objectArrayName);
        Map<String, Object> propertyTypes = nestableObjectArrayNames.get(objectArrayName);
        propertyTypes = resolveClassesForStringPropertyTypes(propertyTypes);
        Map<String, Object> propertyTypesCompiled =
            EventTypeUtility.compileMapTypeProperties(propertyTypes, eventAdapterService);
        eventAdapterService.addNestableObjectArrayType(
            objectArrayName,
            propertyTypesCompiled,
            objectArrayConfig,
            true,
            true,
            true,
            false,
            false,
            false,
            null);
      }
    } catch (EventAdapterException ex) {
      throw new ConfigurationException("Error configuring engine: " + ex.getMessage(), ex);
    }

    // Add plug-in event representations
    Map<URI, ConfigurationPlugInEventRepresentation> plugInReps =
        configSnapshot.getPlugInEventRepresentation();
    for (Map.Entry<URI, ConfigurationPlugInEventRepresentation> entry : plugInReps.entrySet()) {
      String className = entry.getValue().getEventRepresentationClassName();
      Class eventRepClass;
      try {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        eventRepClass = Class.forName(className, true, cl);
      } catch (ClassNotFoundException ex) {
        throw new ConfigurationException(
            "Failed to load plug-in event representation class '" + className + "'", ex);
      }

      Object pluginEventRepObj;
      try {
        pluginEventRepObj = eventRepClass.newInstance();
      } catch (InstantiationException ex) {
        throw new ConfigurationException(
            "Failed to instantiate plug-in event representation class '"
                + className
                + "' via default constructor",
            ex);
      } catch (IllegalAccessException ex) {
        throw new ConfigurationException(
            "Illegal access to instantiate plug-in event representation class '"
                + className
                + "' via default constructor",
            ex);
      }

      if (!(pluginEventRepObj instanceof PlugInEventRepresentation)) {
        throw new ConfigurationException(
            "Plug-in event representation class '"
                + className
                + "' does not implement the required interface "
                + PlugInEventRepresentation.class.getName());
      }

      URI eventRepURI = entry.getKey();
      PlugInEventRepresentation pluginEventRep = (PlugInEventRepresentation) pluginEventRepObj;
      Serializable initializer = entry.getValue().getInitializer();
      PlugInEventRepresentationContext context =
          new PlugInEventRepresentationContext(eventAdapterService, eventRepURI, initializer);

      try {
        pluginEventRep.init(context);
        eventAdapterService.addEventRepresentation(eventRepURI, pluginEventRep);
      } catch (Throwable t) {
        throw new ConfigurationException(
            "Plug-in event representation class '"
                + className
                + "' and URI '"
                + eventRepURI
                + "' did not initialize correctly : "
                + t.getMessage(),
            t);
      }
    }

    // Add plug-in event type names
    Map<String, ConfigurationPlugInEventType> plugInNames = configSnapshot.getPlugInEventTypes();
    for (Map.Entry<String, ConfigurationPlugInEventType> entry : plugInNames.entrySet()) {
      String name = entry.getKey();
      ConfigurationPlugInEventType config = entry.getValue();
      eventAdapterService.addPlugInEventType(
          name, config.getEventRepresentationResolutionURIs(), config.getInitializer());
    }
  }
Beispiel #4
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);
  }