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());
          }
        }
      }
    }
  }
    public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
      final KieSessionModelImpl kSession = new KieSessionModelImpl();
      kSession.name = reader.getAttribute("name");
      kSession.setDefault("true".equals(reader.getAttribute("default")));

      String kSessionType = reader.getAttribute("type");
      kSession.setType(
          kSessionType != null
              ? KieSessionType.valueOf(kSessionType.toUpperCase())
              : KieSessionType.STATEFUL);

      String clockType = reader.getAttribute("clockType");
      if (clockType != null) {
        kSession.setClockType(ClockTypeOption.get(clockType));
      }

      String beliefSystem = reader.getAttribute("beliefSystem");
      if (beliefSystem != null) {
        kSession.setBeliefSystem(BeliefSystemTypeOption.get(beliefSystem));
      }

      String scope = reader.getAttribute("scope");
      if (scope != null) {
        kSession.setScope(scope);
      }

      readNodes(
          reader,
          new AbstractXStreamConverter.NodeReader() {
            public void onNode(HierarchicalStreamReader reader, String name, String value) {
              if ("listeners".equals(name)) {
                while (reader.hasMoreChildren()) {
                  reader.moveDown();
                  String nodeName = reader.getNodeName();
                  ListenerModelImpl listener = readObject(reader, context, ListenerModelImpl.class);
                  listener.setKSession(kSession);
                  listener.setKind(ListenerModel.Kind.fromString(nodeName));
                  kSession.addListenerModel(listener);
                  reader.moveUp();
                }
              } else if ("workItemHandlers".equals(name)) {
                List<WorkItemHandlerModelImpl> wihs =
                    readObjectList(reader, context, WorkItemHandlerModelImpl.class);
                for (WorkItemHandlerModelImpl wih : wihs) {
                  wih.setKSession(kSession);
                  kSession.addWorkItemHandelerModel(wih);
                }
              } else if ("consoleLogger".equals(name)) {
                String consoleLogger = reader.getAttribute("name");
                kSession.setConsoleLogger(consoleLogger == null ? "" : consoleLogger);
              } else if ("fileLogger".equals(name)) {
                FileLoggerModelImpl fileLoggerModel =
                    new FileLoggerModelImpl(reader.getAttribute("file"));
                try {
                  fileLoggerModel.setInterval(Integer.parseInt(reader.getAttribute("interval")));
                } catch (Exception e) {
                }
                try {
                  fileLoggerModel.setThreaded(
                      Boolean.parseBoolean(reader.getAttribute("threaded")));
                } catch (Exception e) {
                }
                kSession.fileLogger = fileLoggerModel;
              }
            }
          });
      return kSession;
    }