/**
* Start time:09:49:43 2009-04-06<br>
* Project: mobicents-isup-stack<br>
*
* @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski
* </a>
*
*/
package org.mobicents.ss7.isup.impl.message.parameter;
import java.io.IOException;
import org.mobicents.ss7.isup.ParameterRangeInvalidException;
import org.mobicents.ss7.isup.message.parameter.RedirectStatus;
/**
* Start time:09:49:43 2009-04-06<br>
* Project: mobicents-isup-stack<br>
*
* @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski
* </a>
*/
public class RedirectStatusImpl extends AbstractParameter implements RedirectStatus{
private byte[] status;
public RedirectStatusImpl() {
super();
// TODO Auto-generated constructor stub
}
public RedirectStatusImpl(byte[] b) throws ParameterRangeInvalidException {
super();
decodeElement(b);
}
/*
* (non-Javadoc)
*
* @see org.mobicents.isup.ISUPComponent#decodeElement(byte[])
*/
public int decodeElement(byte[] b) throws ParameterRangeInvalidException {
try{
setStatus(b);
}catch(Exception e)
{
throw new ParameterRangeInvalidException(e);
}
return b.length;
}
/*
* (non-Javadoc)
*
* @see org.mobicents.isup.ISUPComponent#encodeElement()
*/
public byte[] encodeElement() throws IOException {
for (int index = 0; index < this.status.length; index++) {
this.status[index] = (byte) (this.status[index] & 0x03);
}
this.status[this.status.length - 1] = (byte) ((this.status[this.status.length - 1]) | (0x01 << 7));
return this.status;
}
public byte[] getStatus() {
return status;
}
public void setStatus(byte[] status) {
if (status == null || status.length == 0) {
throw new IllegalArgumentException("byte[] must not be null and length must be greater than 0");
}
this.status = status;
}
public int getStatusIndicator(byte b) {
return b & 0x03;
}
public int getCode() {
return _PARAMETER_CODE;
}
}