try {
Target target = TargetBuilder.INSTANCE.createTarget(
targetTypes, targetName, configContext);
if (target.getType() == TargetType.SERVER ||
target.getType() == TargetType.DAS) {
//If we are operating on a server, ensure that the server is the only entity
//referencing its config
String configName = ServerHelper.getConfigForServer(configContext,
target.getName()).getName();
if (!ConfigAPIHelper.isConfigurationReferencedByServerOnly(configContext,
configName, target.getName())) {
throw new ConfigException(localStrings.getString(
"configurationHasMultipleRefs", target.getName(), configName,
ConfigAPIHelper.getConfigurationReferenceesAsString(
configContext, configName)));
}
} else if (target.getType() == TargetType.CLUSTER) {
//If we are operating on a cluster, ensure that the cluster is the only entity
//referencing its config
String configName = ClusterHelper.getConfigForCluster(configContext,
target.getName()).getName();
if (!ConfigAPIHelper.isConfigurationReferencedByClusterOnly(configContext,
configName, target.getName())) {
throw new ConfigException(localStrings.getString(
"configurationHasMultipleRefs", target.getName(), configName,
ConfigAPIHelper.getConfigurationReferenceesAsString(
configContext, configName)));
}
}
return target;
}
catch (Exception e) {
throw MBeanExceptionFormatter.toMBeanException(e, null);
}