@XStreamAlias("applicationPreferences")
public class ApplicationPreferences {

  private ArrayList<Scanner> scannerList;

  private HashMap<String, Login> saneLogins;

  private SaneServiceIdentity saneServiceIdentity;

  public final HashMap<String, Login> getSaneLogins() {
    if (saneLogins == null) {
      saneLogins = new HashMap<String, Login>();
    }
    return saneLogins;
  }

  public final SaneServiceIdentity getSaneServiceIdentity() {
    if (saneServiceIdentity == null) {
      saneServiceIdentity = new SaneServiceIdentity();
    }
    return saneServiceIdentity;
  }

  public final ArrayList<Scanner> getScannerList() {
    if (scannerList == null) {
      scannerList = new ArrayList<Scanner>();
    }
    return scannerList;
  }

  public final void setSaneService(SaneServiceIdentity saneService) {
    saneServiceIdentity = saneService;
  }

} @XStreamAlias("booleanOption")
public class BooleanOption extends BaseOptions {

  private boolean value;

  public final boolean getValue() {
    return value;
  }

  public final void setValue(boolean value) {
    this.value = value;
  }

} @XStreamAlias("buttonOption")
public class ButtonOption extends GroupOptions {

} @XStreamAlias("groupOption")
public class GroupOption extends GroupOptions {

} @XStreamAlias("integerOption")
public class IntegerOption extends BaseOptions {

  private int value;

  private List<Integer> valueList;

  public final int getValue() {
    return value;
  }

  public final List<Integer> getValueList() {
    return valueList;
  }

  public final void setValue(int value) {
    this.value = value;
  }

  public final void setValueList(List<Integer> valueList) {
    this.valueList = valueList;
  }

} @XStreamAlias("login")
public class Login {

  private String username;

  private String password;

  public final String getPassword() {
    return password;
  }

  public final String getUsername() {
    return username;
  }

  public final void setPassword(String password) {
    this.password = password;
  }

  public final void setUsername(String username) {
    this.username = username;
  }

} @XStreamAlias("optionsOrderValuePair")
public class OptionsOrderValuePair {

  public enum SaneOptionType {
    STRING, BOOLEAN, INTEGER, FIXED, GROUP, BUTTON
  };

  private String key;

  private SaneOptionType saneOptionType;

  private boolean active = true;

  public final String getKey() {
    return key;
  }

  public final SaneOptionType getSaneOptionType() {
    return saneOptionType;
  }

  private String getStatus() {
    if (active) {
      return " (" + Localizer.localize("OptionActiveStatusText") + ")";
    } else {
      return " (" + Localizer.localize("OptionInactiveStatusText") + ")";
    }
  }

  public final boolean isActive() {
    return active;
  }

  public final void setActive(boolean active) {
    this.active = active;
  }

  public final void setKey(String key) {
    this.key = key;
  }

  public final void setSaneOptionType(SaneOptionType saneOptionType) {
    this.saneOptionType = saneOptionType;
  }

  @Override
  public final String toString() {
    return key + getStatus();
  }

} @XStreamAlias("saneServiceIdentity")
public class SaneServiceIdentity {

  private String serviceName = DiscoveryJob.SANE_SERVICE_NAME + "";

  public final String getServiceName() {
    if (serviceName == null) {
      serviceName = DiscoveryJob.SANE_SERVICE_NAME + "";
    }
    return serviceName;
  }

  public final void setServiceName(String serviceName) {
    this.serviceName = serviceName;
  }

} @XStreamAlias("scanner")
public class Scanner extends ScannerOptions {

  private String guid;
  private String description;
  private String serviceName;
  private String remoteAddress;
  private int remotePortNumber;
  private String vendor;
  private String model;
  private String name;
  private String type;
  private int pagesToScan;
  private boolean usingCustomOptions;
  private String batchPrefix = Localizer.localize("ScanFileNamePrefix") + "_"
      + Localizer.localize("TimeStampToken") + "_" + Localizer.localize("PageNumberToken") + "_"
      + Localizer.localize("PageCountToken");

  public Scanner() {
    setGuid((new RandomGUID()).toString());
  }

  public final String getBatchPrefix() {
    return batchPrefix;
  }

  public final String getDescription() {
    return description;
  }

  public final String getGuid() {
    return guid;
  }

  public final String getModel() {
    return model;
  }

  public final String getName() {
    return name;
  }

  public final int getPagesToScan() {
    return pagesToScan;
  }

  public final String getRemoteAddress() {
    return remoteAddress;
  }

  public final int getRemotePortNumber() {
    return remotePortNumber;
  }

  public final String getServiceName() {
    return serviceName;
  }

  public final String getType() {
    return type;
  }

  public final String getVendor() {
    return vendor;
  }

  public final boolean isUsingCustomOptions() {
    return usingCustomOptions;
  }

  public final void setBatchPrefix(String batchPrefix) {
    this.batchPrefix = batchPrefix;
  }

  public final void setDescription(String description) {
    this.description = description;
  }

  public void setGuid(String guid) {
    this.guid = guid;
  }

  public final void setModel(String model) {
    this.model = model;
  }

  public final void setName(String name) {
    this.name = name;
  }

  public final void setPagesToScan(int pagesToScan) {
    this.pagesToScan = pagesToScan;
  }

  public final void setRemoteAddress(String remoteAddress) {
    this.remoteAddress = remoteAddress;
  }

  public final void setRemotePortNumber(int remotePortNumber) {
    this.remotePortNumber = remotePortNumber;
  }

  public final void setServiceName(String serviceName) {
    this.serviceName = serviceName;
  }

  public final void setType(String type) {
    this.type = type;
  }

  public final void setUsingCustomOptions(boolean usingCustomOptions) {
    this.usingCustomOptions = usingCustomOptions;
  }

  public final void setVendor(String vendor) {
    this.vendor = vendor;
  }

} @XStreamAlias("stringOption")
public class StringOption extends BaseOptions {

  private String value;

  public final String getValue() {
    return value;
  }

  public final void setValue(String value) {
    this.value = value;
  }

}
import com.swingsane.preferences.model.ApplicationPreferences;
import com.swingsane.preferences.model.BooleanOption;
import com.swingsane.preferences.model.ButtonOption;
import com.swingsane.preferences.model.GroupOption;
import com.swingsane.preferences.model.IntegerOption;
import com.swingsane.preferences.model.Login;
import com.swingsane.preferences.model.OptionsOrderValuePair;
import com.swingsane.preferences.model.SaneServiceIdentity;
import com.swingsane.preferences.model.Scanner;
import com.swingsane.preferences.model.StringOption;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.mapper.MapperWrapper;
package com.swingsane.preferences;


public final class XStreamUtility {

  public static XStream getXStream() {
    final XStream xstream = loadXStream();
    processAnnotations(xstream);
    return xstream;
  }

  private static XStream loadXStream() {
    XStream xstream = new XStream(new DomDriver("UTF-8")) {
      @Override
      protected MapperWrapper wrapMapper(MapperWrapper next) {
        return new MapperWrapper(next) {
          @Override
          public boolean shouldSerializeMember(@SuppressWarnings("rawtypes") Class definedIn,
              String fieldName) {
            if (definedIn == Object.class) {
              return false;
            }
            return super.shouldSerializeMember(definedIn, fieldName);
          }
        };
      }
    };
    xstream.setMode(XStream.NO_REFERENCES);
    return xstream;
  }

  private static void processAnnotations(XStream xstream) {
    xstream.processAnnotations(ApplicationPreferences.class);
    xstream.processAnnotations(Login.class);