/** * Method to create location from XML representation * * @param xml the XML representation of the location * @return true if successful, false otherwise */ public final boolean setLocationFromXML(String xml) { if (xml == null) return true; // try to deserialize the location from XML try { GeoLocation location = GlobalSerializer.fromXML(GeoLocation.class, xml); setLocation(location); return true; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return false; }
/** * Method to create data from XML * * @param dataType the data type class name * @param xml the XML representation of the data * @return true if successful, false otherwise */ public final boolean setDataFromXML(String dataType, String xml) { // try to deserialize the given data type from XML Class<?> c; try { c = Class.forName(dataType); Object object = GlobalSerializer.fromXML(c, xml); if (object instanceof SampleData) { // we got valid data setData((SampleData) object); return true; } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return false; }