class ChannelManager {
/**
* Returns the other side of a local channel.
* <br>
* Local channels consist of two sides, like
* "Local/1234@from-local-60b5,1" and "Local/1234@from-local-60b5,2" (for Asterisk 1.4) or
* "Local/1234@from-local-60b5;1" and "Local/1234@from-local-60b5;2" (for Asterisk 1.6)
* this method returns the other side.
*
* @param localChannel one side
* @return the other side, or <code>null</code> if not available or if the given channel
* is not a local channel.
*/
AsteriskChannelImpl getOtherSideOfLocalChannel(AsteriskChannel localChannel)
{
final String name;
final char num;
if (localChannel == null)
{
return null;
}
name = localChannel.getName();
if (name == null || !name.startsWith("Local/") || (name.charAt(name.length() - 2) != ',' && name.charAt(name.length() - 2) != ';'))
{
return null;
}
num = name.charAt(name.length() - 1);
if (num == '1')
{
return getChannelImplByName(name.substring(0, name.length() - 1) + "2");
}
else if (num == '2')
{
return getChannelImplByName(name.substring(0, name.length() - 1) + "1");
}
else
{
return null;
}
}
}