View Javadoc

1   /*
2    * Author       :   Arthur Vogels, arthur.vogels@gmail.com
3    *
4    * Purpose      : 	XML support for the GestureSample3D class.
5    *
6    * -----------------------------------------------------------------------
7    *
8    * Revision Information:
9    *
10   * Date             Who         Reason
11   *
12   * Jan 04, 2009     vogelsar    Initial Release
13   *
14   * -----------------------------------------------------------------------
15   *
16   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
17   *
18   * This software is the proprietary information of ETH Zurich.
19   * Use is subject to license terms.
20   * 
21   */
22  
23  
24  package org.ximtec.igesture.core.jdom;
25  
26  import org.jdom.Element;
27  import org.ximtec.igesture.core.Gesture;
28  import org.ximtec.igesture.core.GestureSample3D;
29  import org.ximtec.igesture.util.additions3d.RecordedGesture3D;
30  import org.ximtec.igesture.util.additions3d.jdom.JdomRecordedGesture3D;
31  
32  
33  /**
34   * XML support for the GestureSample3D class.
35   * 
36   * @version 1.0, Jan 2009
37   * @author Arthur Vogels, arthur.vogels@gmail.com
38   */
39  public class JdomGestureSample3D extends Element {
40  
41     public static final String ROOT_TAG = "sample";
42  
43     public static final String NAME_ATTRIBUTE = "name";
44  
45     public static final String UUID_ATTRIBUTE = "id";
46  
47  
48     public JdomGestureSample3D(Gesture<RecordedGesture3D>  sample) {
49        super(ROOT_TAG);
50        setAttribute(NAME_ATTRIBUTE, sample.getName());
51        setAttribute(UUID_ATTRIBUTE, ((GestureSample3D)sample).getId());
52        addContent(new JdomRecordedGesture3D(sample.getGesture()));
53     }
54  
55  
56     public static Gesture<RecordedGesture3D> unmarshal(Element sample) {
57        RecordedGesture3D gesture = null;
58  
59        if (sample.getChild(JdomRecordedGesture3D.ROOT_TAG) != null) {
60           gesture = JdomRecordedGesture3D.unmarshal(sample.getChild(JdomRecordedGesture3D.ROOT_TAG));
61        }
62  
63        final String name = sample.getAttributeValue(NAME_ATTRIBUTE);
64        final String uuid = sample.getAttributeValue(UUID_ATTRIBUTE);
65        final GestureSample3D gestureSample = new GestureSample3D(name, gesture);
66        gestureSample.setId(uuid);
67        return gestureSample;
68  
69     } // unmarshal
70  
71  }