response = Response.status(Response.Status.BAD_REQUEST)
.entity(ise.getMessage()).type(MediaType.TEXT_PLAIN).build();
- } catch (IllegalArgumentException iae) {
- response = Response.status(Response.Status.BAD_REQUEST)
- .entity(iae.getMessage()).type(MediaType.TEXT_PLAIN).build();
-
// This is guard code that should never be reached.
} catch (Exception e) {
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR)
// instance, and attach it to the root element.
root = appendDetailedIDGeneratorInformation(root, instance);
- try {
- resourceRepresentation = prettyPrintXML(doc);
- } catch(Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Error pretty-printing XML: " + e.getMessage());
- }
- resourceRepresentation = doc.asXML();
- }
-
- if (
- resourceRepresentation == null ||
- resourceRepresentation.trim().isEmpty()
- ) {
- response =
- Response.status(Response.Status.INTERNAL_SERVER_ERROR)
- .entity("ID Service returned null or empty ID Generator")
- .type(MediaType.TEXT_PLAIN)
- .build();
- return response;
- }
-
+ resourceRepresentation = prettyPrintXML(doc);
response =
Response.status(Response.Status.OK)
.entity(resourceRepresentation)
.type(MediaType.TEXT_PLAIN)
.build();
- } catch (IllegalArgumentException iae) {
- response =
- Response.status(Response.Status.BAD_REQUEST)
- .entity(iae.getMessage())
- .type(MediaType.TEXT_PLAIN)
- .build();
-
- // This is guard code that should never be reached.
+ // This is guard code that should never be reached.
} catch (Exception e) {
response =
Response.status(Response.Status.INTERNAL_SERVER_ERROR)
listitem = appendSummaryIDGeneratorInformation(listitem, csid);
}
- String summaryList = "";
- try {
- summaryList = prettyPrintXML(doc);
- } catch(Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Error pretty-printing XML: " + e.getMessage());
- }
- summaryList = doc.asXML();
- }
-
- return summaryList;
+ return prettyPrintXML(doc);
}
//////////////////////////////////////////////////////////////////////
generators.get(csid));
}
- String fullList = "";
- try {
- fullList = prettyPrintXML(doc);
- } catch(Exception e) {
- if (logger.isDebugEnabled()) {
- logger.debug("Error pretty-printing XML: " + e.getMessage());
- }
- fullList = doc.asXML();
- }
-
- return fullList;
+ return prettyPrintXML(doc);
}
//////////////////////////////////////////////////////////////////////
*
* @return A pretty printed String representation of an XML document.
*/
- private String prettyPrintXML(Document doc) throws Exception {
+ private String prettyPrintXML(Document doc) {
String xmlStr = "";
try {
xmlStr = formatXML(doc, PRETTY_PRINT_OUTPUT_FORMAT);
+ // If an error occurs during pretty printing, fall back to
+ // returning a default String representation of the XML document.
} catch (Exception e) {
- throw e;
+ if (logger.isDebugEnabled()) {
+ logger.debug("Error pretty-printing XML: " + e.getMessage());
+ }
+ xmlStr = doc.asXML();
}
+
return xmlStr;
}
*
* @return A String representation of an XML document,
* formatted according to the specified output format.
+ *
+ * @throws An Exception if an error occurs in printing
+ * the XML document to a String.
*/
private String formatXML(Document doc, OutputFormat outformat)
throws Exception {
*
* @return The last ID generated that corresponds to the requested ID generator.
*
- * @throws IllegalArgumentException if the requested ID generator could not be found.
+ * @throws DocumentNotFoundException if the requested ID generator
+ * could not be found.
*
* @throws IllegalStateException if a storage-related error occurred.
*/
@Override
- public String readLastID(String csid) throws IllegalArgumentException,
+ public String readLastID(String csid) throws DocumentNotFoundException,
IllegalStateException {
logger.debug("> in readLastID");
boolean moreRows = rs.next();
if (! moreRows) {
- throw new IllegalArgumentException(
+ throw new DocumentNotFoundException(
"ID generator " + "\'" + csid + "\'" + " could not be found.");
}
//////////////////////////////////////////////////////////////////////
/**
- * Adds a new ID generator to persistent storage.
+ * Adds a new ID generator instance to persistent storage.
*
* @param csid An identifier for an ID generator.
*
* @param generator An ID generator, reflecting its current state,
* including the values of its constituent parts.
*
+ * @throws BadRequestException if the provided representation of an
+ * ID generator instance is not in the correct format, contains
+ * invalid values, or otherwise cannot be used.
+ *
* @throws IllegalStateException if a storage-related error occurred.
*/
public void createIDGenerator(String csid, SettableIDGenerator generator)
- throws IllegalArgumentException, IllegalStateException {
+ throws BadRequestException, IllegalStateException {
logger.debug("> in createIDGenerator(String, SettableIDGenerator)");
// @TODO: Add checks for authorization to perform this operation.
if (generator == null) {
- throw new IllegalArgumentException("New ID generator " +
+ throw new BadRequestException("New ID generator " +
"to add cannot be null.");
}
try {
serializedGenerator = IDGeneratorSerializer.serialize(generator);
} catch (IllegalArgumentException e) {
- throw e;
+ throw new BadRequestException(e);
}
try {
}
- //////////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////////
/**
* Adds a new ID generator to persistent storage, from a serialization
* of that generator.
* @param serializedGenerator A serialized ID generator, reflecting its current state,
* including the values of its constituent parts.
*
- * @throws IllegalStateException if a storage-related error occurred.
+ * @throws BadRequestException if the provided representation of an
+ * ID generator instance is not in the correct format, contains
+ * invalid values, or otherwise cannot be used.
+ *
+ * @throws IllegalStateException if a storage-related error occurred.
*/
@Override
public void createIDGenerator(String csid, String serializedGenerator)
- throws IllegalArgumentException, IllegalStateException {
+ throws BadRequestException, IllegalStateException {
logger.debug("> in createIDGenerator(String, String)");
// @TODO Add checks for authorization to perform this operation.
if (serializedGenerator == null || serializedGenerator.equals("")) {
- throw new IllegalArgumentException(
+ throw new BadRequestException(
"Could not understand or parse this representation " +
"of an ID generator.");
}
csid +
"' to the database.");
- // Otherwise, add this new ID generator, as a new record to the database.
+ // Otherwise, add this new ID generator, as a new record to
+ // the database.
} else {
final String SQL_STATEMENT_STRING =
*
* @return A serialized representation of the requested ID generator.
*
- * @throws IllegalArgumentException if the requested ID generator could
+ * @throws DocumentNotFoundException if the requested ID generator could
* not be found.
*
* @throws IllegalStateException if a storage-related error occurred.
*/
@Override
public IDGeneratorInstance readIDGenerator (String csid) throws
- DocumentNotFoundException, IllegalArgumentException,
- IllegalStateException {
+ DocumentNotFoundException, IllegalStateException {
logger.debug("> in readIDGenerator");
}
- //////////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////////
/**
* Returns a list of ID generator instances from persistent storage.
*
* @param generator An ID generator, reflecting its current state,
* including the values of its constituent parts.
*
- * @throws IllegalStateException if a storage-related error occurred.
+ * @throws DocumentNotFoundException if the requested ID generator could
+ * not be found.
+ *
+ * @throws BadRequestException if the provided representation of an
+ * ID generator instance is not in the correct format, contains
+ * invalid values, or otherwise cannot be used.
+ *
+ * @throws IllegalStateException if a storage-related error occurred.
*/
public void updateIDGenerator(String csid, SettableIDGenerator generator)
- throws BadRequestException, IllegalArgumentException, IllegalStateException, DocumentNotFoundException {
+ throws BadRequestException, DocumentNotFoundException,
+ IllegalStateException {
logger.debug("> in updateIDGenerator(String, SettableIDGenerator)");
try {
serializedGenerator = IDGeneratorSerializer.serialize(generator);
} catch (IllegalArgumentException e) {
- throw e;
+ throw new BadRequestException(e);
}
try {
* A serialized ID generator, reflecting its current state,
* including the values of its constituent parts.
*
- * @throws IllegalStateException if a storage-related error occurred.
+ * @throws DocumentNotFoundException if the requested ID generator could
+ * not be found.
+ *
+ * @throws BadRequestException if the provided representation of an
+ * ID generator instance is not in the correct format, contains
+ * invalid values, or otherwise cannot be used.
+ *
+ * @throws IllegalStateException if a storage-related error occurred.
*/
@Override
public void updateIDGenerator(String csid, String serializedGenerator)
throws DocumentNotFoundException, BadRequestException,
- IllegalArgumentException, IllegalStateException {
+ IllegalStateException {
logger.debug("> in updateIDGenerator(String, String)");
*
* @param csid An identifier for an ID generator.
*
- * @throws IllegalStateException if a storage-related error occurred.
+ * @throws DocumentNotFoundException if the requested ID generator could
+ * not be found.
+ *
+ * @throws IllegalStateException if a storage-related error occurred.
*/
public void deleteIDGenerator(String csid)
- throws DocumentNotFoundException, IllegalArgumentException,
- IllegalStateException {
+ throws DocumentNotFoundException, IllegalStateException {
logger.debug("> in deleteIDGenerator");
}
- //////////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////////
/**
* Identifies whether a specified table exists in the database.
*
}
-
}
\ No newline at end of file