Exemplo n.º 1
0
    public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
      KieSessionModelImpl kSession = (KieSessionModelImpl) value;
      writer.addAttribute("name", kSession.getName());
      writer.addAttribute("type", kSession.getType().toString().toLowerCase());
      writer.addAttribute("default", Boolean.toString(kSession.isDefault()));
      if (kSession.getClockType() != null) {
        writer.addAttribute("clockType", kSession.getClockType().getClockType());
      }
      if (kSession.getBeliefSystem() != null) {
        writer.addAttribute(
            "beliefSystem", kSession.getBeliefSystem().getBeliefSystemType().toLowerCase());
      }
      if (kSession.getScope() != null) {
        writer.addAttribute("scope", kSession.getScope());
      }
      if (kSession.getConsoleLogger() != null) {
        writer.startNode("consoleLogger");
        if (kSession.getConsoleLogger().length() > 0) {
          writer.addAttribute("name", kSession.getConsoleLogger());
        }
        writer.endNode();
      }
      if (kSession.getFileLogger() != null) {
        writer.startNode("fileLogger");
        writer.addAttribute("file", kSession.getFileLogger().getFile());
        writer.addAttribute("threaded", "" + kSession.getFileLogger().isThreaded());
        writer.addAttribute("interval", "" + kSession.getFileLogger().getInterval());
        writer.endNode();
      }

      writeObjectList(
          writer,
          context,
          "workItemHandlers",
          "workItemHandler",
          kSession.getWorkItemHandlerModels());

      if (!kSession.getListenerModels().isEmpty()) {
        writer.startNode("listeners");
        for (ListenerModel listener :
            kSession.getListenerModels(ListenerModel.Kind.RULE_RUNTIME_EVENT_LISTENER)) {
          writeObject(writer, context, listener.getKind().toString(), listener);
        }
        for (ListenerModel listener :
            kSession.getListenerModels(ListenerModel.Kind.AGENDA_EVENT_LISTENER)) {
          writeObject(writer, context, listener.getKind().toString(), listener);
        }
        for (ListenerModel listener :
            kSession.getListenerModels(ListenerModel.Kind.PROCESS_EVENT_LISTENER)) {
          writeObject(writer, context, listener.getKind().toString(), listener);
        }
        writer.endNode();
      }
    }
  private void addKieSessionModels(
      ConfigurableListableBeanFactory beanFactory, KieBaseModelImpl kBase) {
    for (String beanDef : beanFactory.getBeanDefinitionNames()) {
      BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanDef);
      if (beanDefinition.getBeanClassName().equalsIgnoreCase(KSessionFactoryBean.class.getName())) {
        String kBaseName = getPropertyValue(beanDefinition, "kBaseName");
        if (kBase.getName().equalsIgnoreCase(kBaseName)) {
          String name = getPropertyValue(beanDefinition, "name");
          String type = getPropertyValue(beanDefinition, "type");
          KieSessionModelImpl kSession = new KieSessionModelImpl(kBase, name);

          kSession.setType(
              !type.isEmpty()
                  ? KieSessionModel.KieSessionType.valueOf(type.toUpperCase())
                  : KieSessionModel.KieSessionType.STATEFUL);
          Map<String, KieSessionModel> rawKieSessionModels = kBase.getRawKieSessionModels();
          rawKieSessionModels.put(kSession.getName(), kSession);
          beanDefinition
              .getPropertyValues()
              .addPropertyValue(new PropertyValue("releaseId", releaseId));

          kSession.setDefault("true".equals(getPropertyValue(beanDefinition, "def")));

          String clockType = getPropertyValue(beanDefinition, "clockType");
          if (!clockType.isEmpty()) {
            kSession.setClockType(ClockTypeOption.get(clockType));
          }

          String scope = getPropertyValue(beanDefinition, "scope");
          if (!scope.isEmpty()) {
            kSession.setScope(scope.trim());
          }
        }
      }
    }
  }