View Javadoc

1   /*
2    * @(#)$Id: JdomSampleDescriptor.java 736 2009-08-14 09:20:17Z kurmannu $
3    *
4    * Author       :   Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose      : 	XML support for the SampleDescriptor 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 java.util.List;
30  
31  import org.jdom.Element;
32  import org.sigtec.ink.Note;
33  import org.ximtec.igesture.core.Gesture;
34  import org.ximtec.igesture.core.SampleDescriptor;
35  
36  
37  /**
38   * XML support for the SampleDescriptor class.
39   * 
40   * @version 1.0, Dec 2006
41   * @author Ueli Kurmann, igesture@uelikurmann.ch
42   * @author Beat Signer, signer@inf.ethz.ch
43   */
44  public class JdomSampleDescriptor extends Element {
45  
46     public static final String ROOT_TAG = "descriptor";
47  
48     public static final String TYPE_ATTRIBUTE = "type";
49  
50     public static final String UUID_ATTRIBUTE = "id";
51  
52  
53     public JdomSampleDescriptor(SampleDescriptor descriptor) {
54        super(ROOT_TAG);
55        setAttribute(TYPE_ATTRIBUTE, descriptor.getType().getName());
56        setAttribute(UUID_ATTRIBUTE, descriptor.getId());
57  
58        for (final Gesture<Note> sample : descriptor.getSamples()) {
59           addContent(new JdomGestureSample(sample));
60        }
61  
62     }
63  
64  
65     @SuppressWarnings("unchecked")
66     public static Object unmarshal(Element descriptor) {
67        String uuid = descriptor.getAttributeValue(UUID_ATTRIBUTE);
68        SampleDescriptor gestureDescriptor = new SampleDescriptor();
69        gestureDescriptor.setId(uuid);
70  
71        for (Element sample : (List<Element>)descriptor.getChildren(JdomGestureSample.ROOT_TAG)) {
72           gestureDescriptor.addSample(JdomGestureSample.unmarshal(sample));
73        }
74  
75        return gestureDescriptor;
76     } // unmarshal
77  
78  }