Search in sources :

Example 1 with DomainExtension

use of com.sun.enterprise.config.serverbeans.DomainExtension 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);
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) Config(com.sun.enterprise.config.serverbeans.Config) ConfigExtension(org.glassfish.api.admin.config.ConfigExtension) DomainExtension(com.sun.enterprise.config.serverbeans.DomainExtension) PropertyVetoException(java.beans.PropertyVetoException) List(java.util.List) Domain(com.sun.enterprise.config.serverbeans.Domain)

Aggregations

Config (com.sun.enterprise.config.serverbeans.Config)1 Domain (com.sun.enterprise.config.serverbeans.Domain)1 DomainExtension (com.sun.enterprise.config.serverbeans.DomainExtension)1 PropertyVetoException (java.beans.PropertyVetoException)1 List (java.util.List)1 ConfigExtension (org.glassfish.api.admin.config.ConfigExtension)1 SingleConfigCode (org.jvnet.hk2.config.SingleConfigCode)1 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)1