1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.ximtec.igesture.core.jdom;
28
29 import org.jdom.Element;
30 import org.sigtec.ink.Note;
31 import org.sigtec.ink.inkml.Ink;
32 import org.sigtec.ink.inkml.Transformer;
33 import org.sigtec.ink.inkml.jdom.JdomInk;
34 import org.sigtec.ink.jdom.JdomNote;
35 import org.ximtec.igesture.core.Gesture;
36 import org.ximtec.igesture.core.GestureSample;
37
38
39
40
41
42
43
44
45
46 public class JdomGestureSample extends Element {
47
48 public static final String ROOT_TAG = "sample";
49
50 public static final String NAME_ATTRIBUTE = "name";
51
52 public static final String UUID_ATTRIBUTE = "id";
53
54
55 public JdomGestureSample(Gesture<Note> sample) {
56 super(ROOT_TAG);
57 setAttribute(NAME_ATTRIBUTE, sample.getName());
58 setAttribute(UUID_ATTRIBUTE, ((GestureSample)sample).getId());
59 addContent(new JdomNote(sample.getGesture()));
60 }
61
62
63 public static GestureSample unmarshal(Element sample) {
64 Note note = null;
65
66 if (sample.getChild(JdomNote.ROOT_TAG) != null) {
67 note = JdomNote.unmarshal(sample.getChild(JdomNote.ROOT_TAG));
68 }
69 else if (sample.getChild(JdomInk.ROOT_TAG) != null) {
70 final Ink ink = JdomInk.unmarshal(sample.getChild(JdomInk.ROOT_TAG));
71 note = Transformer.fromInkML(ink);
72 }
73
74 final String name = sample.getAttributeValue(NAME_ATTRIBUTE);
75 final String uuid = sample.getAttributeValue(UUID_ATTRIBUTE);
76 final GestureSample gestureSample = new GestureSample(name, note);
77 gestureSample.setId(uuid);
78 return gestureSample;
79 }
80
81 }