Example usage for java.rmi.server ExportException ExportException

List of usage examples for java.rmi.server ExportException ExportException

Introduction

In this page you can find the example usage for java.rmi.server ExportException ExportException.

Prototype

public ExportException(String s) 

Source Link

Document

Constructs an ExportException with the specified detail message.

Usage

From source file:org.sigmah.server.servlet.exporter.models.ProjectModelHandler.java

@Override
public String exportModel(OutputStream outputStream, String identifier, EntityManager em) throws Exception {

    String name = "";

    if (identifier == null) {
        throw new ExportException("The identifier is missing.");
    }/*from   www. ja  va  2s  .  c  om*/

    final Integer projectModelId = Integer.parseInt(identifier);

    final ProjectModel hibernateModel = em.find(ProjectModel.class, projectModelId);

    if (hibernateModel == null)
        throw new ExportException("No project model is associated with the identifier '" + identifier + "'.");

    name = hibernateModel.getName();

    // Removing superfluous links
    hibernateModel.setVisibilities(null);

    // Stripping hibernate proxies from the model.
    final ProjectModel realModel = Realizer.realize(hibernateModel);

    // Serialization
    try {

        final ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(realModel);

    } catch (Exception ex) {
        throw new Exception("An error occured while serializing the project model " + projectModelId, ex);
    }

    return name;
}

From source file:org.sigmah.server.servlet.exporter.models.ProjectReportModelHandler.java

@Override
public String exportModel(OutputStream outputStream, String identifier, EntityManager em) throws Exception {

    String name = "";

    if (identifier != null) {
        final Integer projectReportModelId = Integer.parseInt(identifier);

        final ProjectReportModel hibernateModel = em.find(ProjectReportModel.class, projectReportModelId);

        if (hibernateModel == null)
            throw new ExportException(
                    "No project report model is associated with the identifier '" + identifier + "'.");

        name = hibernateModel.getName();

        // Stripping hibernate proxies from the model.
        final ProjectReportModel realModel = Realizer.realize(hibernateModel);
        // Serialization
        try {//w  w w .  ja  va  2s  .c o  m
            final ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
            objectOutputStream.writeObject(realModel);
        } catch (Exception ex) {
            throw new Exception("An error occured while serializing the project model " + projectReportModelId,
                    ex);
        }

    } else {
        throw new Exception("The identifier is missing.");
    }

    return name;
}