View Javadoc

1   /*
2    * @(#)$Id: JdomGestureSample.java 736 2009-08-14 09:20:17Z kurmannu $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      : 	XML support for the GestureSample class.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Dec 26, 2006     ukurmann    Initial Release
15   * Mar 22, 2007     bsigner     Cleanup
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
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   * XML support for the GestureSample class.
41   * 
42   * @version 1.0, Dec 2006
43   * @author Ueli Kurmann, igesture@uelikurmann.ch
44   * @author Beat Signer, signer@inf.ethz.ch
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     } // unmarshal
80  
81  }