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 List<ListenerModel> getListenerModels(ListenerModel.Kind kind) { List<ListenerModel> listeners = new ArrayList<ListenerModel>(); for (ListenerModel listener : getListenerModels()) { if (listener.getKind() == kind) { listeners.add(listener); } } return listeners; }