Search in sources :

Example 16 with KSessionModel

use of org.kie.workbench.common.services.shared.kmodule.KSessionModel in project kie-wb-common by kiegroup.

the class KBaseConverter method marshal.

public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    KBaseModel kBase = (KBaseModel) value;
    writer.addAttribute("name", kBase.getName());
    writer.addAttribute("default", Boolean.toString(kBase.isDefault()));
    if (kBase.getEventProcessingMode() != null) {
        writer.addAttribute("eventProcessingMode", kBase.getEventProcessingMode().getMode());
    }
    if (kBase.getEqualsBehavior() != null) {
        writer.addAttribute("equalsBehavior", kBase.getEqualsBehavior().toString());
    }
    if (kBase.getDeclarativeAgenda() != null) {
        writer.addAttribute("declarativeAgenda", kBase.getDeclarativeAgenda().toString());
    }
    if (kBase.getScope() != null) {
        writer.addAttribute("scope", kBase.getScope());
    }
    if (!kBase.getPackages().isEmpty()) {
        StringBuilder buf = new StringBuilder();
        boolean first = true;
        for (String pkg : kBase.getPackages()) {
            if (first) {
                first = false;
            } else {
                buf.append(", ");
            }
            buf.append(pkg);
        }
        writer.addAttribute("packages", buf.toString());
    }
    if (!kBase.getIncludes().isEmpty()) {
        StringBuilder sb = new StringBuilder();
        boolean insertComma = false;
        for (String include : kBase.getIncludes()) {
            if (insertComma) {
                sb.append(", ");
            }
            sb.append(include);
            if (!insertComma) {
                insertComma = true;
            }
        }
        writer.addAttribute("includes", sb.toString());
    }
    for (KSessionModel kSessionModel : kBase.getKSessions()) {
        writeObject(writer, context, "ksession", kSessionModel);
    }
}
Also used : KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) KBaseModel(org.kie.workbench.common.services.shared.kmodule.KBaseModel)

Example 17 with KSessionModel

use of org.kie.workbench.common.services.shared.kmodule.KSessionModel in project kie-wb-common by kiegroup.

the class KSessionConverter method unmarshal.

public Object unmarshal(HierarchicalStreamReader reader, final UnmarshallingContext context) {
    final KSessionModel kSession = new KSessionModel();
    kSession.setName(reader.getAttribute("name"));
    kSession.setDefault("true".equals(reader.getAttribute("default")));
    String kSessionType = reader.getAttribute("type");
    kSession.setType(kSessionType != null ? kSessionType : "stateful");
    String clockType = reader.getAttribute("clockType");
    if (clockType != null) {
        kSession.setClockType(ClockTypeOption.get(clockType));
    }
    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();
                    kSession.getListeners().add(readObject(reader, context, ListenerModel.class));
                    reader.moveUp();
                }
            } else if ("workItemHandlers".equals(name)) {
                kSession.getWorkItemHandelerModels().addAll(readObjectList(reader, context, WorkItemHandlerModel.class));
            }
        // else if ("consoleLogger".equals(name)){
        // kSession.setLogger(readObject(reader, context, ConsoleLogger.class));
        // } else if ("fileLogger".equals(name)){
        // kSession.setLogger(readObject(reader, context, FileLogger.class));
        // }
        }
    });
    return kSession;
}
Also used : KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel) WorkItemHandlerModel(org.guvnor.common.services.project.model.WorkItemHandlerModel) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) AbstractXStreamConverter(org.drools.core.util.AbstractXStreamConverter)

Example 18 with KSessionModel

use of org.kie.workbench.common.services.shared.kmodule.KSessionModel in project kie-wb-common by kiegroup.

the class KSessionConverter method marshal.

public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    KSessionModel kSession = (KSessionModel) value;
    writer.addAttribute("name", kSession.getName());
    writer.addAttribute("type", kSession.getType());
    writer.addAttribute("default", Boolean.toString(kSession.isDefault()));
    if (kSession.getClockType() != null) {
        writer.addAttribute("clockType", kSession.getClockType().getClockTypeAsString());
    }
    if (kSession.getScope() != null) {
        writer.addAttribute("scope", kSession.getScope().toString());
    }
    writeObjectList(writer, context, "workItemHandlers", "workItemHandler", kSession.getWorkItemHandelerModels());
    if (!kSession.getListeners().isEmpty()) {
        writer.startNode("listeners");
        for (ListenerModel listener : kSession.getListeners()) {
            writeObject(writer, context, listener.getKind().toString(), listener);
        }
        writer.endNode();
    }
}
Also used : ListenerModel(org.kie.workbench.common.services.shared.kmodule.ListenerModel) KSessionModel(org.kie.workbench.common.services.shared.kmodule.KSessionModel)

Aggregations

KSessionModel (org.kie.workbench.common.services.shared.kmodule.KSessionModel)18 Test (org.junit.Test)9 KBaseModel (org.kie.workbench.common.services.shared.kmodule.KBaseModel)7 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)2 AbstractXStreamConverter (org.drools.core.util.AbstractXStreamConverter)2 ArrayList (java.util.ArrayList)1 WorkItemHandlerModel (org.guvnor.common.services.project.model.WorkItemHandlerModel)1 ListenerModel (org.kie.workbench.common.services.shared.kmodule.ListenerModel)1