private String onNameSpaceSelected(ISession session, String nameSpace, String aliasNameTemplate)
{
try
{
ISQLAlias curAlias = session.getAlias();
String urlPrefix = "jdbc:Cache://";
if (false == curAlias.getUrl().startsWith(urlPrefix))
{
String msg = "URL of this session does not start with " + urlPrefix + ".\nCannot create alias";
JOptionPane.showMessageDialog(session.getApplication().getMainFrame(), msg);
return "";
}
if (urlPrefix.length() >= curAlias.getUrl().lastIndexOf(':'))
{
String msg = "Could not find server in this session's URL " + curAlias.getUrl() + ".\nURL must match jdbc:Cache://<server>:<port>/<namespace>\n" +
"Cannot create alias.";
JOptionPane.showMessageDialog(session.getApplication().getMainFrame(), msg);
return "";
}
String server = curAlias.getUrl().substring(urlPrefix.length(), curAlias.getUrl().lastIndexOf(':'));
ISQLAlias alias = session.getApplication().getDataCache().createAlias(IdentifierFactory.getInstance().createIdentifier());
alias.setName(aliasNameTemplate.replaceAll("%server", server).replaceAll("%namespace", nameSpace));
alias.setDriverIdentifier(curAlias.getDriverIdentifier());
alias.setUserName(curAlias.getUserName());
alias.setPassword(curAlias.getPassword());
alias.setUrl(curAlias.getUrl().substring(0, curAlias.getUrl().lastIndexOf('/') + 1) + nameSpace);
alias.setAutoLogon(curAlias.isAutoLogon());
session.getApplication().getDataCache().addAlias(alias);
return alias.getName();
}
catch (Exception e)
{
throw new RuntimeException(e);
}