public static void readUser( JSONObject user, AbstractModel model, LongProperty idProperty, StringProperty userProperty) throws JSONException { long id = user.getLong("id"); if (id == ActFmPreferenceService.userId()) { model.setValue(idProperty, 0L); if (userProperty != null) model.setValue(userProperty, ""); } else { model.setValue(idProperty, id); if (userProperty != null) model.setValue(userProperty, user.toString()); } }
@Override public AbstractModel clone() { AbstractModel clone; try { clone = (AbstractModel) super.clone(); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } if (setValues != null) { clone.setValues = new ContentValues(setValues); } if (values != null) { clone.values = new ContentValues(values); } return clone; }
@Override public Void visitDouble(Property<Double> property, AbstractModel data) { try { Double value = data.getValue(property); String valueString = (value == null) ? XML_NULL : value.toString(); xml.attribute(null, property.name, valueString); } catch (UnsupportedOperationException e) { // didn't read this value, do nothing } catch (IllegalArgumentException | IllegalStateException | IOException e) { throw new RuntimeException(e); } return null; }
@Override public Void visitLong(Property<Long> property, AbstractModel data) { try { xml.attribute(null, property.name, data.getValue(property).toString()); } catch (UnsupportedOperationException e) { // didn't read this value, do nothing } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (IllegalStateException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return null; }
@Override public Void visitString(Property<String> property, AbstractModel data) { try { String value = data.getValue(property); if (value == null) { return null; } xml.attribute(null, property.name, value); } catch (UnsupportedOperationException e) { // didn't read this value, do nothing Timber.v(e, e.getMessage()); } catch (IllegalArgumentException | IOException | IllegalStateException e) { throw new RuntimeException(e); } return null; }
/** * Turn a model into xml attributes * * @param model */ private void serializeModel( AbstractModel model, Property<?>[] properties, Property<?>... excludes) { outer: for (Property<?> property : properties) { for (Property<?> exclude : excludes) if (property.name.equals(exclude.name)) continue outer; try { property.accept(xmlWritingVisitor, model); } catch (Exception e) { Log.e( "astrid-exporter", //$NON-NLS-1$ "Caught exception while reading " + property.name + //$NON-NLS-1$ " from " + model.getDatabaseValues(), e); //$NON-NLS-1$ } } }