View Javadoc

1   /*
2    * @(#)$Id: JdomPoint3D.java
3    *  
4    * Author       :   Arthur Vogels, arthur.vogels@gmail.com
5    *
6    * Purpose      :   Constructs an XML representation of a Point3D object.
7    *                  The 'timestamp' element is optional.
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date             Who         Reason
14   *
15   * Jan 04, 2009     vogelsar    Initial Release
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  package org.ximtec.igesture.util.additions3d.jdom;
27  
28  import org.jdom.Element;
29  import org.sigtec.jdom.element.JdomDoubleElement;
30  import org.sigtec.jdom.element.JdomLongElement;
31  import org.ximtec.igesture.util.additions3d.Point3D;
32  
33  
34  /**
35   * Constructs an XML representation for a Point3D object. The 'timestamp' element is optional.
36   * @version 1.0, Jan 2009
37   * @author Arthur Vogels, arthur.vogels@gmail.com
38   */
39  public class JdomPoint3D extends Element {
40  
41     public static final String ROOT_TAG = "point3D";
42     public static final String POINT_ELEMENT_X = "x";
43     public static final String POINT_ELEMENT_Y = "y";
44     public static final String POINT_ELEMENT_Z = "z";
45     public static final String POINT_ELEMENT_TIMESTAMP = "timestamp";
46  
47     public JdomPoint3D(Point3D point) {
48        super(ROOT_TAG);
49        addContent(new JdomDoubleElement(POINT_ELEMENT_X, point.getX()));
50        addContent(new JdomDoubleElement(POINT_ELEMENT_Y, point.getY()));
51        addContent(new JdomDoubleElement(POINT_ELEMENT_Z, point.getZ()));
52  
53        if (point.hasTimeStamp()) {
54           addContent(new JdomLongElement(POINT_ELEMENT_TIMESTAMP, point
55                 .getTimeStamp()));
56        }
57  
58     } // JdomPoint3D
59  
60  
61     public static Point3D unmarshal(Element point) {
62        Point3D newPoint = new Point3D(Double.parseDouble(point
63              .getChildText(POINT_ELEMENT_X)), Double.parseDouble(point
64              .getChildText(POINT_ELEMENT_Y)), Double.parseDouble(point
65                      .getChildText(POINT_ELEMENT_Z)), 0);
66        setTimestamp(newPoint, point);
67        return newPoint;
68     } // unmarshal
69  
70  
71     private static void setTimestamp(Point3D point, Element source) {
72        Element timestamp = source.getChild(POINT_ELEMENT_TIMESTAMP);
73  
74        if (timestamp != null) {
75           point.setTimeStamp(Long.parseLong(timestamp.getText()));
76        }
77  
78     } // setTimestamp
79  
80  }