Refactored exception in XMLSikevaDB.
This commit is contained in:
parent
e939664d89
commit
49d906a0b8
1 changed files with 101 additions and 73 deletions
|
@ -19,6 +19,7 @@
|
|||
package fr.devinsy.sikevadb.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
@ -45,17 +46,16 @@ public class XMLSikevaDB
|
|||
private static final Logger logger = LoggerFactory.getLogger(XMLSikevaDB.class);
|
||||
|
||||
/**
|
||||
* Saves a net in a file.
|
||||
* Export.
|
||||
*
|
||||
* @param out
|
||||
* the out
|
||||
* @param source
|
||||
* Source.
|
||||
*
|
||||
* @throws Exception
|
||||
* the exception
|
||||
* the source
|
||||
* @throws SikevaDBException
|
||||
* the sikeva DB exception
|
||||
*/
|
||||
public static void export(final OutputStream out, final SikevaDB source) throws Exception
|
||||
public static void export(final OutputStream out, final SikevaDB source) throws SikevaDBException
|
||||
{
|
||||
//
|
||||
String fileName = "sikevadb-" + DateTime.now().toString("yyyy-MM-dd-HH'h'mm'mn'ss's'") + ".xml.zip";
|
||||
|
@ -65,19 +65,18 @@ public class XMLSikevaDB
|
|||
}
|
||||
|
||||
/**
|
||||
* Saves a net in a file.
|
||||
* Export.
|
||||
*
|
||||
* @param out
|
||||
* the out
|
||||
* @param source
|
||||
* Source.
|
||||
* the source
|
||||
* @param fileName
|
||||
* the file name
|
||||
*
|
||||
* @throws Exception
|
||||
* the exception
|
||||
* @throws SikevaDBException
|
||||
* the sikeva DB exception
|
||||
*/
|
||||
public static void export(final OutputStream out, final SikevaDB source, final String fileName) throws Exception
|
||||
public static void export(final OutputStream out, final SikevaDB source, final String fileName) throws SikevaDBException
|
||||
{
|
||||
if (out == null)
|
||||
{
|
||||
|
@ -105,12 +104,23 @@ public class XMLSikevaDB
|
|||
//
|
||||
write(target, source);
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
throw new SikevaDBException("Problem writing element.", exception);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (target != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
target.close();
|
||||
}
|
||||
catch (IOException exception)
|
||||
{
|
||||
logger.warn("Problem closing stream.", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +136,7 @@ public class XMLSikevaDB
|
|||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public static void importData(final SikevaDB database, final File file) throws Exception
|
||||
public static void importData(final SikevaDB database, final File file)
|
||||
{
|
||||
// XMLReader in = null;
|
||||
// try {
|
||||
|
@ -145,16 +155,14 @@ public class XMLSikevaDB
|
|||
* @param in
|
||||
* the in
|
||||
* @return the element
|
||||
*
|
||||
* @throws XMLStreamException
|
||||
* the XML stream exception
|
||||
* @throws XMLBadFormatException
|
||||
* the XML bad format exception
|
||||
* @throws SikevaDBException
|
||||
*/
|
||||
public static Element readElement(final XMLReader in) throws XMLStreamException, XMLBadFormatException
|
||||
public static Element readElement(final XMLReader in) throws SikevaDBException
|
||||
{
|
||||
Element result;
|
||||
|
||||
try
|
||||
{
|
||||
//
|
||||
XMLTag tag = in.readStartTag("element");
|
||||
|
||||
|
@ -197,6 +205,15 @@ public class XMLSikevaDB
|
|||
|
||||
//
|
||||
in.readEndTag("element");
|
||||
}
|
||||
catch (XMLStreamException exception)
|
||||
{
|
||||
throw new SikevaDBException("Problem reading element.", exception);
|
||||
}
|
||||
catch (XMLBadFormatException exception)
|
||||
{
|
||||
throw new SikevaDBException("Problem reading element.", exception);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
|
@ -209,25 +226,26 @@ public class XMLSikevaDB
|
|||
* the target
|
||||
* @param in
|
||||
* the in
|
||||
* @throws XMLBadFormatException
|
||||
* @throws XMLStreamException
|
||||
* @throws SikevaDBException
|
||||
*
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public static void readElements(final SikevaDB target, final XMLReader in) throws Exception
|
||||
public static void readElements(final SikevaDB target, final XMLReader in) throws SikevaDBException
|
||||
{
|
||||
try
|
||||
{
|
||||
//
|
||||
XMLTag list = in.readListTag("elements");
|
||||
|
||||
//
|
||||
if (list.getType() != TagType.EMPTY)
|
||||
{
|
||||
//
|
||||
while (in.hasNextStartTag("element"))
|
||||
{
|
||||
|
||||
//
|
||||
Element element = readElement(in);
|
||||
|
||||
//
|
||||
target.put(element);
|
||||
}
|
||||
|
||||
|
@ -235,6 +253,15 @@ public class XMLSikevaDB
|
|||
in.readEndTag("elements");
|
||||
}
|
||||
}
|
||||
catch (XMLStreamException exception)
|
||||
{
|
||||
throw new SikevaDBException("Problem reading element.", exception);
|
||||
}
|
||||
catch (XMLBadFormatException exception)
|
||||
{
|
||||
throw new SikevaDBException("Problem reading element.", exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write.
|
||||
|
@ -300,11 +327,12 @@ public class XMLSikevaDB
|
|||
* the out
|
||||
* @param source
|
||||
* the source
|
||||
* @throws SikevaDBException
|
||||
*
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
public static void write(final XMLWriter out, final SikevaDB source) throws Exception
|
||||
public static void write(final XMLWriter out, final SikevaDB source) throws SikevaDBException
|
||||
{
|
||||
if (out == null)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue