Skip to content

Commit

Permalink
Removes the wrapper class DummyErrorBody
Browse files Browse the repository at this point in the history
  • Loading branch information
CesarCoelho committed Oct 13, 2023
1 parent 0f3733a commit 5d42e42
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import java.io.Serializable;
import org.ccsds.moims.mo.mal.structures.Attribute;
import org.ccsds.moims.mo.mal.structures.UInteger;
import org.ccsds.moims.mo.mal.transport.MALEncodedBody;
import org.ccsds.moims.mo.mal.transport.MALEncodedElement;
import org.ccsds.moims.mo.mal.transport.MALErrorBody;

/**
* Represents a MAL error.
*/
public class MOErrorException extends Exception implements Serializable {
public class MOErrorException extends Exception implements Serializable, MALErrorBody {

private final UInteger errorNumber;
private final Object extraInformation;
Expand Down Expand Up @@ -72,6 +75,31 @@ public Object getExtraInformation() {
return extraInformation;
}

@Override
public MOErrorException getError() throws MALException {
return this;
}

@Override
public int getElementCount() {
return 1;
}

@Override
public Object getBodyElement(int index, Object element) throws MALException {
return this;
}

@Override
public MALEncodedElement getEncodedBodyElement(int index) throws MALException {
return null;
}

@Override
public MALEncodedBody getEncodedBody() throws MALException {
return null;
}

@Override
public String toString() {
final StringBuilder buf = new StringBuilder();
Expand Down
69 changes: 0 additions & 69 deletions mal-impl/src/main/java/esa/mo/mal/impl/ips/DummyErrorBody.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import esa.mo.mal.impl.MALContextFactoryImpl;
import java.util.Map;
import java.util.logging.Level;
import org.ccsds.moims.mo.mal.MALHelper;
import org.ccsds.moims.mo.mal.MALInteractionException;
import org.ccsds.moims.mo.mal.MOErrorException;
import org.ccsds.moims.mo.mal.structures.InteractionType;
Expand All @@ -35,8 +34,6 @@
*/
public abstract class IPConsumerHandler {

protected static final DummyErrorBody ERROR_BODY_INCORRECT_STATE
= new DummyErrorBody(new MOErrorException(MALHelper.INCORRECT_STATE_ERROR_NUMBER, null));
protected final boolean isSynchronous;
protected final OperationResponseHolder responseHolder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.logging.Level;
import org.ccsds.moims.mo.mal.MALException;
import org.ccsds.moims.mo.mal.MALHelper;
import org.ccsds.moims.mo.mal.MALInteractionException;
import org.ccsds.moims.mo.mal.MALInvokeOperation;
import org.ccsds.moims.mo.mal.MOErrorException;
Expand Down Expand Up @@ -75,7 +76,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException {
}
} else {
finished = true;
listener.invokeAckErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos);
MOErrorException incorrectStateError = new MOErrorException(
MALHelper.INCORRECT_STATE_ERROR_NUMBER,
"The received message is not an INVOKE_ACK_STAGE!");
listener.invokeAckErrorReceived(header, incorrectStateError, qos);
}
return;
}
Expand All @@ -93,7 +97,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException {
}

// If it is not ACK, nor RESPONSE, then something went wrong!
listener.invokeResponseErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos);
MOErrorException incorrectStateError = new MOErrorException(
MALHelper.INCORRECT_STATE_ERROR_NUMBER,
"The received message is not an INVOKE_ACK_STAGE, nor INVOKE_RESPONSE_STAGE!");
listener.invokeResponseErrorReceived(header, incorrectStateError, qos);
} catch (MALException ex) {
// nothing we can do with this
MALContextFactoryImpl.LOGGER.log(Level.WARNING,
Expand All @@ -109,9 +116,9 @@ public synchronized void handleError(final MALMessageHeader hdr,
} else {
try {
if (!receivedAck) {
responseHolder.getListener().invokeAckErrorReceived(hdr, new DummyErrorBody(error), qosMap);
responseHolder.getListener().invokeAckErrorReceived(hdr, error, qosMap);
} else {
responseHolder.getListener().invokeResponseErrorReceived(hdr, new DummyErrorBody(error), qosMap);
responseHolder.getListener().invokeResponseErrorReceived(hdr, error, qosMap);
}
} catch (MALException ex) {
// not a lot we can do with this at this stage apart from log it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
package esa.mo.mal.impl.ips;

import esa.mo.mal.impl.MALContextFactoryImpl;
import static esa.mo.mal.impl.ips.IPConsumerHandler.ERROR_BODY_INCORRECT_STATE;
import java.util.Map;
import java.util.logging.Level;
import org.ccsds.moims.mo.mal.MALException;
import org.ccsds.moims.mo.mal.MALHelper;
import org.ccsds.moims.mo.mal.MALInteractionException;
import org.ccsds.moims.mo.mal.MALProgressOperation;
import org.ccsds.moims.mo.mal.MOErrorException;
Expand Down Expand Up @@ -76,7 +76,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException {
}
} else {
finished = true;
listener.progressAckErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos);
MOErrorException incorrectStateError = new MOErrorException(
MALHelper.INCORRECT_STATE_ERROR_NUMBER,
"The received message is not a PROGRESS_ACK_STAGE!");
listener.progressAckErrorReceived(header, incorrectStateError, qos);
}
return;
}
Expand Down Expand Up @@ -104,7 +107,10 @@ public void handleStage(final MALMessage msg) throws MALInteractionException {
}

// If it is not ACK, PROGRESS, nor RESPONSE, then something went wrong!
listener.progressUpdateErrorReceived(header, ERROR_BODY_INCORRECT_STATE, qos);
MOErrorException incorrectStateError = new MOErrorException(
MALHelper.INCORRECT_STATE_ERROR_NUMBER,
"The received message is not a PROGRESS_ACK_STAGE, nor PROGRESS_UPDATE_STAGE, nor PROGRESS_RESPONSE_STAGE!");
listener.progressUpdateErrorReceived(header, incorrectStateError, qos);
} catch (MALException ex) {
// nothing we can do with this
MALContextFactoryImpl.LOGGER.log(Level.WARNING,
Expand All @@ -120,9 +126,9 @@ public synchronized void handleError(final MALMessageHeader hdr,
} else {
try {
if (!receivedAck) {
responseHolder.getListener().progressAckErrorReceived(hdr, new DummyErrorBody(error), qosMap);
responseHolder.getListener().progressAckErrorReceived(hdr, error, qosMap);
} else {
responseHolder.getListener().progressResponseErrorReceived(hdr, new DummyErrorBody(error), qosMap);
responseHolder.getListener().progressResponseErrorReceived(hdr, error, qosMap);
}
} catch (MALException ex) {
// not a lot we can do with this at this stage apart from log it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public synchronized void handleError(final MALMessageHeader hdr,
responseHolder.signalError(error);
} else {
try {
responseHolder.getListener().submitErrorReceived(hdr,
new DummyErrorBody(error), qosMap);
responseHolder.getListener().submitErrorReceived(hdr, error, qosMap);
} catch (MALException ex) {
// not a lot we can do with this at this stage apart from log it
MALContextFactoryImpl.LOGGER.log(Level.WARNING,
Expand Down

0 comments on commit 5d42e42

Please sign in to comment.