| 1 | package com.hammurapi.eventbus.tests.familyties; |
| 2 | |
| 3 | import com.hammurapi.convert.AbstractReflectiveAtomicConvertersBundle; |
| 4 | import com.hammurapi.convert.Converter; |
| 5 | import com.hammurapi.convert.ConverterMethod; |
| 6 | import com.hammurapi.eventbus.snapshot.CompositeEvent; |
| 7 | import com.hammurapi.eventbus.snapshot.Event; |
| 8 | import com.hammurapi.eventbus.snapshot.SnapshotFactory; |
| 9 | import com.hammurapi.eventbus.tests.familyties.model.Person; |
| 10 | import com.hammurapi.eventbus.tests.familyties.model.Relative; |
| 11 | |
| 12 | public class FamilyTiesConvertersBundle extends AbstractReflectiveAtomicConvertersBundle { |
| 13 | |
| 14 | /** |
| 15 | * Converter method for relative. |
| 16 | * @param relative |
| 17 | * @return |
| 18 | */ |
| 19 | @ConverterMethod |
| 20 | public CompositeEvent convertToEvent(Relative relative, Converter master) { |
| 21 | CompositeEvent ce = SnapshotFactory.eINSTANCE.createCompositeEvent(); |
| 22 | int idx = relative.getClass().getName().lastIndexOf('.'); |
| 23 | ce.setName(relative.getClass().getName().substring(idx+1)); |
| 24 | ce.setDetails(relative.toString()); |
| 25 | |
| 26 | Event subj = master.convert(relative.getSubject(), Event.class, null); |
| 27 | subj.setPartRole("subject"); |
| 28 | subj.setId(""); |
| 29 | ce.getParts().add(subj); |
| 30 | |
| 31 | Event obj = master.convert(relative.getObject(), Event.class, null); |
| 32 | obj.setPartRole("object"); |
| 33 | obj.setId(""); |
| 34 | ce.getParts().add(obj); |
| 35 | |
| 36 | return ce; |
| 37 | } |
| 38 | |
| 39 | @ConverterMethod |
| 40 | public Event convertToEvent(Person person) { |
| 41 | Event ret = SnapshotFactory.eINSTANCE.createEvent(); |
| 42 | ret.setName(person.getName()); |
| 43 | ret.setDetails(person.toString()); |
| 44 | return ret; |
| 45 | } |
| 46 | } |