this.separator = separator;
// Subtopic cannot be zero length.
if (subtopic.length() == 0)
{
ServiceException se = new ServiceException();
se.setMessage(10554, new Object[] {subtopic});
throw se;
}
// Validate subtopic format if it contains a separator.
else if ((separator != null) && (subtopic.indexOf(separator) != -1))
{
hierarchical = true;
/*
* Each token must have non-zero length, meaning no leading or trailing
* separator or empty subtopics in between.
*/
if (subtopic.startsWith(separator) ||
subtopic.endsWith(separator) ||
(subtopic.indexOf(separator + separator) != -1))
{
ServiceException se = new ServiceException();
se.setMessage(10554, new Object[] {subtopic});
throw se;
}
/*
* If a token contains the SUBTOPIC_WILDCARD, that token may not
* contain any additional characters.
* I.e. chat.* is OK, chat.f* is not OK (assuming a separator of '.').
*/
StringTokenizer tokenizer = new StringTokenizer(subtopic, separator);
while (tokenizer.hasMoreTokens())
{
String token = tokenizer.nextToken();
if (token.indexOf(SUBTOPIC_WILDCARD) != -1)
{
if (!token.equals(SUBTOPIC_WILDCARD))
{
ServiceException se = new ServiceException();
se.setMessage(10554, new Object[] {subtopic});
throw se;
}
else
{
hasSubtopicWildcard = true;
}
}
}
}
// Non-hierarchical subtopics cannot contain subtopic wildcard unless
// that is the only value, "*", indicating a match for any subtopic.
else if (subtopic.indexOf(SUBTOPIC_WILDCARD) != -1)
{
if (!subtopic.equals(SUBTOPIC_WILDCARD))
{
ServiceException se = new ServiceException();
se.setMessage(10554, new Object[] {subtopic});
throw se;
}
else
{
hasSubtopicWildcard = true;