Difference between revisions of "READERNAME ExceptionHandler.java"

From RifidiWiki

Jump to: navigation, search
(invalidCommandError)
 
(13 intermediate revisions by one other user not shown)
Line 1: Line 1:
This class should extend GenericExceptionHandler.
+
[[category:developerDoc]][[category:emulatorDoc]]
 +
This class should extend GenericExceptionHandler.  This page goes through each of the four methods in GenericExceptionHandler and describes in detail what each one does and how it should be implemented.  The first three methods must be implemented by the class that extends it, and the last class may (and probably should be) implemented by the subclass.
  
It should override three methods:
+
=CommandNotFoundError=
  
==CommandNotFoundError==
+
This exception is thrown in the [[Command Flow|CommandAdapter]] if a command is sent to the reader that is not defined in the reader.xml
 
+
This exception is thrown in the [[CommandFlow|CommandAdapter]] if a command is sent to the reader that is not defined in the reader.xml
+
  
 
<pre>public abstract ArrayList<Object> commandNotFoundError(ArrayList<Object> arg, CommandObject obj);</pre>
 
<pre>public abstract ArrayList<Object> commandNotFoundError(ArrayList<Object> arg, CommandObject obj);</pre>
  
===Arguments===
+
==Arguments==
 
#arg - The incoming command
 
#arg - The incoming command
 
#obj - The incoming command object
 
#obj - The incoming command object
  
===Return Value===
+
==Return Value==
 
An array of objects where the first object in the array is a message to be sent back to the client.
 
An array of objects where the first object in the array is a message to be sent back to the client.
  
===Reference Implementation===
+
==Reference Implementation==
 
This is the commandNotFoundError in the alien reader
 
This is the commandNotFoundError in the alien reader
 
<pre>
 
<pre>
Line 34: Line 33:
 
</pre>
 
</pre>
  
==invalidCommandError==
+
=InvalidCommandError=
This exception is thrown in the [[CommandFlow|CommandAdapter]] if a command is in the reader.xml but does not have the correct form. For example, if it does not have a required argument
+
This exception is thrown in the [[Command Flow|CommandAdapter]] if a command is in the reader.xml but does has and invalid argument.  
  
 
<pre>public abstract ArrayList<Object> invalidCommandError(ArrayList<Object> arg, String value, CommandObject obj);</pre>
 
<pre>public abstract ArrayList<Object> invalidCommandError(ArrayList<Object> arg, String value, CommandObject obj);</pre>
  
===Arguments===
+
==Arguments==
 
#arg - The incoming command
 
#arg - The incoming command
 
#obj - The incoming command object
 
#obj - The incoming command object
  
===Return Value===
+
==Return Value==
 
An array of objects where the first object in the array is a message to be sent back to the client.
 
An array of objects where the first object in the array is a message to be sent back to the client.
  
===Reference Implementation===
+
==Reference Implementation==
 
See the above implementation for the commandNotFound.  The handling of this error will likely be the same, but the message might be slightly different.
 
See the above implementation for the commandNotFound.  The handling of this error will likely be the same, but the message might be slightly different.
  
==malformedMessageError==
+
=MalformedMessageError=
 +
Tiis exception is thrown in the [[Command Flow|CommandAdapter]] if a command is in the reader.xml but is missing a required argument
 +
 
 
<pre>public abstract ArrayList<Object> malformedMessageError(ArrayList<Object> arg, CommandObject obj);</pre>
 
<pre>public abstract ArrayList<Object> malformedMessageError(ArrayList<Object> arg, CommandObject obj);</pre>
 +
 +
==Arguments==
 +
#arg - The incoming command
 +
#obj - The incoming command object
 +
 +
==Return Value==
 +
An array of objects where the first object in the array is a message to be sent back to the client.
 +
 +
==Reference Implementation==
 +
See the above implementation for the commandNotFound.  The handling of this error will likely be the same, but the message might be slightly different.
 +
 +
=MethodInvocationError=
 +
This exception is thrown in the [[Command Flow|CommandAdapter]] if something goes wrong in the handler method while executing a command.  It often happens if there is a null pointer exception thrown somewhere in the handler method.  While it is not required to implement this method, it is a good idea to do so, so that a proper error message can be sent back to the reader if something like that happens
 +
 +
<pre>public CommandObject methodInvocationError(ArrayList<Object> arg,CommandObject obj)</pre>
 +
 +
==Arguments==
 +
#arg - The incoming command
 +
#obj - The incoming command object
 +
 +
==Return Value==
 +
An array of objects where the first object in the array is a message to be sent back to the client.
 +
 +
==Reference Implementation==
 +
This is a reference implementation from the LLRPExceptionHandler.  The ErrorMessage object is an LLRP specific message that the reader is required to send back to the client if an error happens.
 +
<pre>
 +
public CommandObject methodInvocationError(ArrayList<Object> arg,
 +
CommandObject obj) {
 +
ErrorMessage em = new ErrorMessage();
 +
LLRPStatus llrpstat = new LLRPStatus();
 +
llrpstat.setErrorCode((short) 100);
 +
char[] c = obj.getCurrentQueryName().toCharArray();
 +
byte[] com = new byte[c.length];
 +
for (int i = 0; i < c.length; i++) {
 +
com[i] = (byte) c[i];
 +
}
 +
 +
llrpstat.setErrorDescription("Internal error in Rifidi "
 +
+ "when processing a message of type "
 +
+ LLRPUtilities.calculateMessageNumber(com)
 +
+ " Please report error at "
 +
+ "rifidi sourceforge page");
 +
em.setLLRPStatusParam(llrpstat);
 +
 +
 +
obj.getReturnValue().add(em);
 +
return obj;
 +
}
 +
</pre>

Latest revision as of 12:44, 6 May 2009

This class should extend GenericExceptionHandler. This page goes through each of the four methods in GenericExceptionHandler and describes in detail what each one does and how it should be implemented. The first three methods must be implemented by the class that extends it, and the last class may (and probably should be) implemented by the subclass.

CommandNotFoundError

This exception is thrown in the CommandAdapter if a command is sent to the reader that is not defined in the reader.xml

public abstract ArrayList<Object> commandNotFoundError(ArrayList<Object> arg, CommandObject obj);

Arguments

  1. arg - The incoming command
  2. obj - The incoming command object

Return Value

An array of objects where the first object in the array is a message to be sent back to the client.

Reference Implementation

This is the commandNotFoundError in the alien reader

	public ArrayList<Object> commandNotFoundError(ArrayList<Object> arg,
			CommandObject obj) {
		String message = "";
		for (Object i : arg) {
			message += i.toString();
		}
		message = "Error 1: Command not understood" + message;
		ArrayList<Object> returnValue = new ArrayList<Object>();
		returnValue.add(message);
                return returnValue;

	}

InvalidCommandError

This exception is thrown in the CommandAdapter if a command is in the reader.xml but does has and invalid argument.

public abstract ArrayList<Object> invalidCommandError(ArrayList<Object> arg, String value, CommandObject obj);

Arguments

  1. arg - The incoming command
  2. obj - The incoming command object

Return Value

An array of objects where the first object in the array is a message to be sent back to the client.

Reference Implementation

See the above implementation for the commandNotFound. The handling of this error will likely be the same, but the message might be slightly different.

MalformedMessageError

Tiis exception is thrown in the CommandAdapter if a command is in the reader.xml but is missing a required argument

public abstract ArrayList<Object> malformedMessageError(ArrayList<Object> arg, CommandObject obj);

Arguments

  1. arg - The incoming command
  2. obj - The incoming command object

Return Value

An array of objects where the first object in the array is a message to be sent back to the client.

Reference Implementation

See the above implementation for the commandNotFound. The handling of this error will likely be the same, but the message might be slightly different.

MethodInvocationError

This exception is thrown in the CommandAdapter if something goes wrong in the handler method while executing a command. It often happens if there is a null pointer exception thrown somewhere in the handler method. While it is not required to implement this method, it is a good idea to do so, so that a proper error message can be sent back to the reader if something like that happens

public CommandObject methodInvocationError(ArrayList<Object> arg,CommandObject obj)

Arguments

  1. arg - The incoming command
  2. obj - The incoming command object

Return Value

An array of objects where the first object in the array is a message to be sent back to the client.

Reference Implementation

This is a reference implementation from the LLRPExceptionHandler. The ErrorMessage object is an LLRP specific message that the reader is required to send back to the client if an error happens.

	public CommandObject methodInvocationError(ArrayList<Object> arg,
			CommandObject obj) {
		ErrorMessage em = new ErrorMessage();
		LLRPStatus llrpstat = new LLRPStatus();
		llrpstat.setErrorCode((short) 100);
		char[] c = obj.getCurrentQueryName().toCharArray();
		byte[] com = new byte[c.length];
		for (int i = 0; i < c.length; i++) {
			com[i] = (byte) c[i];
		}

		llrpstat.setErrorDescription("Internal error in Rifidi "
				+ "when processing a message of type "
				+ LLRPUtilities.calculateMessageNumber(com)
				+ " Please report error at "
				+ "rifidi sourceforge page");
		em.setLLRPStatusParam(llrpstat);

		
		obj.getReturnValue().add(em);
		return obj;
	}
Personal tools