String methodName;
String destinationContext;
if (type == Topic.class)
{
destinationContext = "topic";
methodName = "createTopic";
}
else if (type == Queue.class)
{
destinationContext = "queue";
methodName = "createQueue";
}
else
{
// type was not a Topic or Queue, bad user
throw new IllegalArgumentException
("Expected javax.jms.Queue or javax.jms.Topic: " + type);
}
ObjectName destinationManagerName = new ObjectName("jboss.mq:service=DestinationManager");
KernelAbstraction kernel = KernelAbstractionFactory.getInstance();
// invoke the server to create the destination
Object result = kernel.invoke(destinationManagerName,
methodName,
new Object[]{jndiSuffix},
new String[]{"java.lang.String"});
InitialContext jndiContext = InitialContextFactory.getInitialContext();
String binding = destinationContext + "/" + jndiSuffix;
try
{
jndiContext.lookup(binding);
}
catch (NamingException e)
{
jndiContext.rebind(binding, result);
}