From 3f716382064cb69e7225baeefc5534885ffa7ab2 Mon Sep 17 00:00:00 2001 From: "manuele.simi" Date: Thu, 1 Feb 2018 03:42:42 +0000 Subject: [PATCH] Make the deserializers final. Reduce their visibility at package level. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/resource-management/resource-manager@162830 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../deserializer/ErrorCodeDeserializer.java | 7 ++----- .../deserializer/ErrorEntityManager.java | 18 +++++++++++++++++- .../deserializer/ExceptionDeserializer.java | 4 ++-- .../deserializer/package-info.java | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorCodeDeserializer.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorCodeDeserializer.java index 5e90ffe..4900f75 100644 --- a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorCodeDeserializer.java +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorCodeDeserializer.java @@ -1,12 +1,9 @@ -/** - * - */ package org.gcube.resourcemanagement.manager.io.codeexceptions.deserializer; import org.gcube.resourcemanagement.manager.io.codeexceptions.ErrorCode; /** - * Don't forget to comment! + * Deserializer for {@link ErrorCode}. * * @author Manuele Simi (ISTI CNR) * @@ -22,7 +19,7 @@ final class ErrorCodeDeserializer { * The error code, if any * @return the error code or null */ - public static ErrorCode deserialize(int id, String message) { + protected static ErrorCode deserialize(int id, String message) { if (id != 1) { return new ErrorCode() { diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorEntityManager.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorEntityManager.java index 6ddd2e8..8d81747 100644 --- a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorEntityManager.java +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ErrorEntityManager.java @@ -6,7 +6,7 @@ import org.gcube.resourcemanagement.manager.io.codeexceptions.ErrorCode; import org.gcube.resourcemanagement.manager.io.codeexceptions.SerializableErrorEntity; /** - * Don't forget to comment! + * Manager for extracting information held inside a {@link SerializableErrorEntity}. * * @author Manuele Simi (ISTI CNR) * @@ -21,18 +21,34 @@ public class ErrorEntityManager { this.entity = entity; } + /** + * Checks if there is an {@link Exception} in the entity. + * @return true if the entity holds an exception, false otherwise + */ public boolean hasException() { return Objects.nonNull(this.entity.getExceptionClass()); } + /** + * Gets the {@link Exception} inside the entity. + * @return the exception or null + */ public E getException() { return ExceptionDeserializer.deserialize(this.entity.getExceptionClass(),this.entity.getMessage()); } + /** + * Checks if there is an {@link ErrorCode} in the entity. + * @return true if the entity holds an errorcode, false otherwise + */ public boolean hasErrorCode() { return this.entity.getId() != -1; } + /** + * Gets the {@link ErrorCode} inside the entity. + * @return the error code or null + */ public ErrorCode getErrorCode(){ return ErrorCodeDeserializer.deserialize(this.entity.getId(), this.entity.getMessage()); } diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ExceptionDeserializer.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ExceptionDeserializer.java index 42320f5..bed4f3b 100644 --- a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ExceptionDeserializer.java +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/ExceptionDeserializer.java @@ -8,7 +8,7 @@ import java.lang.reflect.InvocationTargetException; * @author Manuele Simi (ISTI CNR) * */ -class ExceptionDeserializer { +final class ExceptionDeserializer { /** * @@ -17,7 +17,7 @@ class ExceptionDeserializer { @SuppressWarnings("unchecked") - public static E deserialize(String exceptionClass, String message) { + protected static E deserialize(String exceptionClass, String message) { try { final Class[] ctorParams = {String.class}; return (E) Class.forName(exceptionClass).getConstructor(ctorParams).newInstance(message); diff --git a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/package-info.java b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/package-info.java index 8bbb6b3..3151265 100644 --- a/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/package-info.java +++ b/io/src/main/java/org/gcube/resourcemanagement/manager/io/codeexceptions/deserializer/package-info.java @@ -1,6 +1,6 @@ /** - * Don't forget to comment! + * Helper classes to deserialize the information held inside a {@link org.gcube.resourcemanagement.manager.io.codeexceptions.SerializableErrorEntity}. * * @author Manuele Simi (ISTI CNR) *