jndiNameForConnectionPool = jndiName + JNDINAME_APPENDER;
ActionReport subReport = report.addSubActionsReport();
ConnectorResource cresource = null;
Resource res = ConnectorsUtil.getResourceByName(domain.getResources(), ConnectorResource.class, jndiName);
if (res instanceof ConnectorResource) {
cresource = (ConnectorResource) res;
}
/* for (ConnectorResource cr : connResources) {
if (cr.getJndiName().equals(jndiName))
cresource = cr;
} */
if (cresource == null) {
ParameterMap params = new ParameterMap();
params.set("jndi_name", jndiName);
params.set("DEFAULT", jndiName);
params.set("target", target);
commandRunner.getCommandInvocation("delete-admin-object", subReport, context.getSubject()).parameters(params).execute();
if (ActionReport.ExitCode.FAILURE.equals(subReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("delete.jms.resource.cannotDeleteJMSAdminObject",
"Unable to Delete Admin Object."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
} else {
if (!cascade) {
Collection<ConnectorResource> connectorResources = domain.getResources().getResources(ConnectorResource.class);
String connPoolName = jndiName + JNDINAME_APPENDER;
int count = 0;
for (ConnectorResource resource : connectorResources) {
if (connPoolName.equals(resource.getPoolName())) {
count ++;
if (count > 1)
break;
}
}
if (count > 1) {
report.setMessage(localStrings.getLocalString("found.more.connector.resources",
"Some connector resources are referencing connection pool {0}. Use 'cascade' option to delete them", connPoolName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
ActionReport listReport = habitat.getService(ActionReport.class);
ParameterMap listParams = new ParameterMap();
listParams.set("target", target);
commandRunner.getCommandInvocation("list-jms-resources", listReport, context.getSubject()).parameters(listParams).execute();
if (ActionReport.ExitCode.FAILURE.equals(listReport.getActionExitCode())) {
report.setMessage(localStrings.getLocalString("list.jms.resources.fail",
"Unable to list JMS Resources"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
Properties extraProps = listReport.getExtraProperties();
if (extraProps != null && extraProps.size() > 0) {
boolean resourceExist = false;
for (int i=0; i<extraProps.size(); i++) {
List<Map<String, String>> nameList = (List) extraProps.get("jmsResources");
for (Map<String,String> m : nameList) {
String jndi = (String) m.get("name");
if (jndiName.equals(jndi)) {
resourceExist = true;
break;
}
}
if (resourceExist)
break;
}
if (!resourceExist) {
report.setMessage(localStrings.getLocalString("jms.resources.not.found",
"JMS Resource {0} not found", jndiName));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// Delete the connector resource and connector connection pool
String defPoolName = jndiNameForConnectionPool;
String poolName = cresource.getPoolName();
if (poolName != null && poolName.equals(defPoolName)) {
ParameterMap params = new ParameterMap();
params.set("DEFAULT", jndiName);
params.set("connector_resource_name", jndiName);
params.set("target", target);