Package org.simpleframework.xml

Examples of org.simpleframework.xml.Serializer


  public void performExport(File filePath, File backup_dir, boolean includeFiles) throws Exception {
    if (!backup_dir.exists()) {
      backup_dir.mkdirs();
    }
    Serializer simpleSerializer = new Persister();
   
    /*
     * ##################### Backup Organizations
     */
    writeList(simpleSerializer, backup_dir, "organizations.xml",
        "organisations", organisationDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### Backup Users
     */
    exportUsers(backup_dir, usersDao.getAllBackupUsers());

    /*
     * ##################### Backup Room
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(RoomType.class, RoomTypeConverter.class);
     
      writeList(serializer, backup_dir, "rooms.xml", "rooms", roomDao.get());
    }

    /*
     * ##################### Backup Room Organizations
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(Organisation.class, OrganisationConverter.class);
      registry.bind(Room.class, RoomConverter.class);
     
      writeList(serializer, backup_dir, "rooms_organisation.xml",
          "room_organisations", roomOrganisationDao.get());
    }

    /*
     * ##################### Backup Appointments
     */
    {
      List<Appointment> list = appointmentDao.getAppointments();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(AppointmentCategory.class, AppointmentCategoryConverter.class);
      registry.bind(User.class, UserConverter.class);
      registry.bind(AppointmentReminderTyps.class, AppointmentReminderTypeConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getStart().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "appointements.xml", "appointments", list);
    }

    /*
     * ##################### Backup Meeting Members
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Appointment.class, AppointmentConverter.class);
     
      writeList(serializer, backup_dir, "meetingmembers.xml",
          "meetingmembers", meetingMemberDao.getMeetingMembers());
    }

    /*
     * ##################### LDAP Configs
     */
    writeList(simpleSerializer, backup_dir, "ldapconfigs.xml",
        "ldapconfigs", ldapConfigDao.get());

    /*
     * ##################### Cluster servers
     */
    writeList(simpleSerializer, backup_dir, "servers.xml", "servers", serverDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### OAuth2 servers
     */
    writeList(simpleSerializer, backup_dir, "oauth2servers.xml", "oauth2servers", auth2Dao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### Private Messages
     */
    {
      List<PrivateMessage> list = privateMessagesDao.get(0, Integer.MAX_VALUE);
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "privateMessages.xml",
          "privatemessages", list);
    }

    /*
     * ##################### Private Message Folders
     */
    writeList(simpleSerializer, backup_dir, "privateMessageFolder.xml",
        "privatemessagefolders", privateMessageFolderDao.get(0, Integer.MAX_VALUE));

    /*
     * ##################### User Contacts
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
     
      writeList(serializer, backup_dir, "userContacts.xml",
          "usercontacts", userContactsDao.getUserContacts());
    }

    /*
     * ##################### File-Explorer
     */
    {
      List<FileExplorerItem> list = fileExplorerItemDao.getFileExplorerItems();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "fileExplorerItems.xml",
          "fileExplorerItems", list);
    }

    /*
     * ##################### Recordings
     */
    {
      List<FlvRecording> list = flvRecordingDao.getAllFlvRecordings();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getInserted().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "flvRecordings.xml",
          "flvrecordings", list);
    }

    /*
     * ##################### Polls
     */
    {
      List<RoomPoll> list = pollManager.getPollListBackup();
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      registry.bind(PollType.class, PollTypeConverter.class);
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getCreated().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "roompolls.xml", "roompolls", list);
    }

    /*
     * ##################### Config
     */
    {
      List<Configuration> list = configurationDao.getConfigurations(
          0, Integer.MAX_VALUE, "c.configuration_id", true);
      Registry registry = new Registry();
      registry.bind(State.class, StateConverter.class);
      registry.bind(User.class, UserConverter.class);
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      if (list != null && list.size() > 0) {
        registry.bind(list.get(0).getStarttime().getClass(), DateConverter.class);
      }
     
      writeList(serializer, backup_dir, "configs.xml", "configs", list);
    }
   
    /*
     * ##################### Chat
     */
    {
      Registry registry = new Registry();
      Strategy strategy = new RegistryStrategy(registry);
      Serializer serializer = new Persister(strategy);
 
      registry.bind(User.class, UserConverter.class);
      registry.bind(Room.class, RoomConverter.class);
      List<ChatMessage> list = chatDao.get(0, Integer.MAX_VALUE);
      if (list != null && list.size() > 0) {
View Full Code Here


  }
 
  public void exportUsers(OutputStream os, List<User> list) throws Exception {
    Registry registry = new Registry();
    Strategy strategy = new RegistryStrategy(registry);
    Serializer serializer = new Persister(strategy);

    registry.bind(Organisation.class, OrganisationConverter.class);
    registry.bind(State.class, StateConverter.class);
    if (list != null && list.size() > 0) {
      registry.bind(list.get(0).getRegdate().getClass(), DateConverter.class);
View Full Code Here

   *
   * @param object property annotated object
   * @return XML representation of the object
   */
  public static String generateRequest(Object object) {
    Serializer serializer = new Persister();
    StringWriter writer = new StringWriter();
    try {
      serializer.write(object, writer);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to generate XML request!", e);
      return null;
    }
    return writer.toString();
View Full Code Here

   *
   * @param object property annotated object
   * @param outputStream the stream to write the XML to
   */
  public static void generateRequest(Object object, OutputStream outputStream) {
    Serializer serializer = new Persister();
    try {
      serializer.write(object, outputStream);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to generate XML request!", e);
    }
  }
View Full Code Here

   * @param xml string containing the XML to be converted to object
   * @param clazz the type of the return object
   * @return
   */
  public static <T> T parseResponse(String xml, Class<T> clazz) {
    Serializer serializer = new Persister(new JWebThumbMatcher());
    try {
      return serializer.read(clazz, xml);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to parse XML response!", e);
      return null;
    }
  }
View Full Code Here

   * @param inputStream the stream to read the XML from
   * @param clazz the type of the return object
   * @return
   */
  public static <T> T parseResponse(InputStream inputStream, Class<T> clazz) {
    Serializer serializer = new Persister(new JWebThumbMatcher());
    try {
      return serializer.read(clazz, inputStream);
    } catch (Exception e) {
      LOGGER.log(Level.SEVERE, "Failed to parse XML response!", e);
      return null;
    }
  }
View Full Code Here

     * @return a reconstituted GATKRunReport from reportAsXML
     * @throws Exception if parsing fails for any reason
     */
    @Ensures("result != null")
    protected static GATKRunReport deserializeReport(final InputStream stream) throws Exception {
        final Serializer serializer = new Persister();
        return serializer.read(GATKRunReport.class, stream);
    }
View Full Code Here

     *
     * @param stream an output stream to write the report to
     */
    @Requires("stream != null")
    protected boolean postReportToStream(final OutputStream stream) {
        final Serializer serializer = new Persister();
        try {
            serializer.write(this, stream);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
View Full Code Here

      addPackage(pkg);
    }
  }
 
  private void savePackages(File file) throws Exception {
    Serializer serializer = createSerializer();
    PackagesConfigurationHolder holder = new PackagesConfigurationHolder();
    holder.packages = new ArrayList<Package>(packages.values());
    serializer.write(holder, new ByteArrayOutputStream());
    serializer.write(holder, file);
  }
View Full Code Here

    serializer.write(holder, new ByteArrayOutputStream());
    serializer.write(holder, file);
  }
 
  private void loadParts(File file) throws Exception {
    Serializer serializer = createSerializer();
    PartsConfigurationHolder holder = serializer.read(PartsConfigurationHolder.class, file);
    for (Part part : holder.parts) {
      addPart(part);
    }
  }
View Full Code Here

TOP

Related Classes of org.simpleframework.xml.Serializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.