use of org.glassfish.api.admin.config.ConfigExtension in project Payara by payara.
the class DeleteModuleConfigCommand method deleteTopLevelExtensionByType.
private void deleteTopLevelExtensionByType(Config config, final String className, Class configBeanType) {
if (ConfigExtension.class.isAssignableFrom(configBeanType)) {
if (config.checkIfExtensionExists(configBeanType)) {
try {
ConfigSupport.apply(new SingleConfigCode<Config>() {
@Override
public Object run(Config param) throws PropertyVetoException, TransactionFailure {
List<ConfigExtension> configExtensions;
configExtensions = param.getExtensions();
for (ConfigExtension ext : configExtensions) {
String configExtensionClass = GlassFishConfigBean.unwrap(ext).getProxyType().getSimpleName();
if (configExtensionClass.equals(className)) {
configExtensions.remove(ext);
break;
}
}
return configExtensions;
}
}, config);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure e) {
String actual = e.getMessage();
String msg = localStrings.getLocalString("delete.module.config.failed.to.delete.config", DEFAULT_FORMAT, serviceName, actual);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
} else {
report.setMessage(localStrings.getLocalString("delete.module.config.no.configuration", "No customized configuration exist for this service nor the default configuration has been added to the domain.xml."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
} else if (DomainExtension.class.isAssignableFrom(configBeanType)) {
if (domain.checkIfExtensionExists(configBeanType)) {
try {
ConfigSupport.apply(new SingleConfigCode<Domain>() {
@Override
public Object run(Domain param) throws PropertyVetoException, TransactionFailure {
List<DomainExtension> domainExtensions;
domainExtensions = param.getExtensions();
for (DomainExtension ext : domainExtensions) {
String configExtensionClass = GlassFishConfigBean.unwrap(ext).getProxyType().getSimpleName();
if (configExtensionClass.equals(className)) {
domainExtensions.remove(ext);
break;
}
}
return domainExtensions;
}
}, domain);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
} catch (TransactionFailure e) {
String actual = e.getMessage();
String msg = localStrings.getLocalString("delete.module.config.failed.to.delete.config", DEFAULT_FORMAT, serviceName, actual);
report.setMessage(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
}
} else {
report.setMessage(localStrings.getLocalString("delete.module.config.no.configuration", "No customized configuration exist for this service nor the default configuration has been added to the domain.xml."));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
}
Aggregations