org.deckfour.xes.xstream.XEventConverter Maven / Gradle / Ivy
Show all versions of SEWOL Show documentation
/*
* OpenXES
*
* The reference implementation of the XES meta-model for event
* log data management.
*
* Copyright (c) 2008 Christian W. Guenther ([email protected])
*
*
* LICENSE:
*
* This code is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* EXEMPTION:
*
* The use of this software can also be conditionally licensed for
* other programs, which do not satisfy the specified conditions. This
* requires an exemption from the general license, which may be
* granted on a per-case basis.
*
* If you want to license the use of this software with a program
* incompatible with the LGPL, please contact the author for an
* exemption at the following email address:
* [email protected]
*
*/
package org.deckfour.xes.xstream;
import org.deckfour.xes.id.XID;
import org.deckfour.xes.model.XAttributeMap;
import org.deckfour.xes.model.XEvent;
import org.deckfour.xes.model.impl.XEventImpl;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
/**
* XStream converter for serializing events.
*
*
* For more information about XStream and its serialization API, please see http://xstream.codehaus.org/.
*
* @author Christian W. Guenther ([email protected])
*
*/
public class XEventConverter extends XConverter {
/*
* (non-Javadoc)
*
* @see
* com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object,
* com.thoughtworks.xstream.io.HierarchicalStreamWriter,
* com.thoughtworks.xstream.converters.MarshallingContext)
*/
public void marshal(Object obj, HierarchicalStreamWriter writer,
MarshallingContext context) {
XEvent event = (XEvent) obj;
writer.addAttribute("xid", event.getID().toString());
if (event.getAttributes().size() > 0) {
writer.startNode("XAttributeMap");
context.convertAnother(event.getAttributes(), XesXStreamPersistency.attributeMapConverter);
writer.endNode();
}
}
/*
* (non-Javadoc)
*
* @see
* com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks
* .xstream.io.HierarchicalStreamReader,
* com.thoughtworks.xstream.converters.UnmarshallingContext)
*/
public Object unmarshal(HierarchicalStreamReader reader,
UnmarshallingContext context) {
XEventImpl event = new XEventImpl();
String id = reader.getAttribute("xid");
event.setID(XID.parse(id));
if (reader.hasMoreChildren()) {
reader.moveDown();
XAttributeMap attributes = (XAttributeMap) context.convertAnother(
event, XAttributeMap.class, XesXStreamPersistency.attributeMapConverter);
event.setAttributes(attributes);
reader.moveUp();
}
return event;
}
/*
* (non-Javadoc)
*
* @see
* com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.
* lang.Class)
*/
@SuppressWarnings("unchecked")
public boolean canConvert(Class c) {
return XEvent.class.isAssignableFrom(c);
}
/*
* (non-Javadoc)
*
* @see
* org.deckfour.xes.xstream.XConverter#registerAliases(com.thoughtworks.
* xstream.XStream)
*/
@Override
public void registerAliases(XStream stream) {
stream.aliasType("XEvent", XEvent.class);
}
}