Search in sources :

Example 26 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class ModuleConfigSource method deleteValue.

public boolean deleteValue(String propertyName) throws TransactionFailure {
    boolean result = false;
    Application app = domainConfiguration.getApplications().getApplication(configurationName);
    if (app != null) {
        Module m = app.getModule(moduleName);
        for (Property object : m.getProperty()) {
            if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
                ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(m), (ConfigBean) ConfigBean.unwrap(object));
                result = true;
            }
        }
    }
    return result;
}
Also used : Module(com.sun.enterprise.config.serverbeans.Module) Application(com.sun.enterprise.config.serverbeans.Application) Property(org.jvnet.hk2.config.types.Property)

Example 27 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class ApplicationConfigSource method deleteValue.

public boolean deleteValue(String propertyName) throws TransactionFailure {
    boolean result = false;
    Application app = domainConfiguration.getApplications().getApplication(configurationName);
    if (app != null) {
        for (Property object : app.getProperty()) {
            if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
                ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(app), (ConfigBean) ConfigBean.unwrap(object));
                result = true;
            }
        }
    }
    return result;
}
Also used : Application(com.sun.enterprise.config.serverbeans.Application) Property(org.jvnet.hk2.config.types.Property)

Example 28 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class ServerConfigSource method deleteValue.

public boolean deleteValue(String propertyName) throws TransactionFailure {
    boolean result = false;
    Server config = domainConfiguration.getServerNamed(configurationName);
    if (config != null) {
        for (Property object : config.getProperty()) {
            if ((PROPERTY_PREFIX + propertyName).equals(object.getName())) {
                ConfigSupport.deleteChild((ConfigBean) ConfigBean.unwrap(config), (ConfigBean) ConfigBean.unwrap(object));
                result = true;
            }
        }
    }
    return result;
}
Also used : Server(com.sun.enterprise.config.serverbeans.Server) Property(org.jvnet.hk2.config.types.Property)

Example 29 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class WriteableView method commit.

/**
 * Commit this Transaction.
 *
 * @param t the transaction commiting.
 * @throws TransactionFailure
 *          if the transaction commit failed
 */
@Override
public synchronized List<PropertyChangeEvent> commit(Transaction t) throws TransactionFailure {
    if (currentTx == t) {
        currentTx = null;
    }
    // a key attribute must be non-null and have length >= 1
    final ConfigBean master = getMasterView();
    final String keyStr = master.model.key;
    if (keyStr != null) {
        final String key = stripMarkers(keyStr);
        final String value = getPropertyValue(key);
        if (value == null) {
            throw new TransactionFailure("Key value cannot be null: " + key);
        }
        if (value.length() == 0) {
            throw new TransactionFailure("Key value cannot be empty string: " + key);
        }
    }
    try {
        List<PropertyChangeEvent> appliedChanges = new ArrayList<>();
        for (PropertyChangeEvent event : changedAttributes.values()) {
            ConfigModel.Property property = bean.model.findIgnoreCase(event.getPropertyName());
            ConfigBeanInterceptor<?> interceptor = bean.getOptionalFeature(ConfigBeanInterceptor.class);
            try {
                if (interceptor != null) {
                    interceptor.beforeChange(event);
                }
            } catch (PropertyVetoException e) {
                throw new TransactionFailure(e.getMessage(), e);
            }
            property.set(bean, event.getNewValue());
            if (interceptor != null) {
                interceptor.afterChange(event, System.currentTimeMillis());
            }
            appliedChanges.add(event);
        }
        for (ProtectedList<?> entry : changedCollections.values()) {
            commitListChanges(entry, appliedChanges);
        }
        changedAttributes.clear();
        changedCollections.clear();
        return appliedChanges;
    } catch (TransactionFailure e) {
        throw e;
    } catch (Exception e) {
        throw new TransactionFailure(e.getMessage(), e);
    } finally {
        bean.getLock().unlock();
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) PropertyChangeEvent(java.beans.PropertyChangeEvent) Property(org.jvnet.hk2.config.ConfigModel.Property) PropertyVetoException(java.beans.PropertyVetoException)

Example 30 with ConfigBean

use of org.jvnet.hk2.config.ConfigBean in project Payara by payara.

the class DeleteModuleConfigCommand method deleteDependentConfigElement.

private void deleteDependentConfigElement(final ConfigBeanDefaultValue defaultValue) {
    Class parentClass = configModularityUtils.getOwningClassForLocation(defaultValue.getLocation());
    final Class configBeanClass = configModularityUtils.getClassForFullName(defaultValue.getConfigBeanClassName());
    final Method m = configModularityUtils.findSuitableCollectionGetter(parentClass, configBeanClass);
    if (m != null) {
        try {
            final ConfigBeanProxy parent = configModularityUtils.getOwningObject(defaultValue.getLocation());
            ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {

                @Override
                public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
                    List col = null;
                    ConfigBeanProxy configBean = null;
                    try {
                        col = (List) m.invoke(param);
                        if (col != null) {
                            configBean = configModularityUtils.getCurrentConfigBeanForDefaultValue(defaultValue);
                        }
                    } catch (Exception e) {
                        String message = localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements ");
                        report.setMessage(message);
                        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
                        LOG.log(Level.INFO, DELETE_MODULE_CONFIG_FAILED_DELETING_DEPENDENT, e);
                    }
                    if (configBean != null) {
                        boolean deleted = configModularityUtils.deleteConfigurationForConfigBean(configBean, col, defaultValue);
                        if (!deleted) {
                            for (int i = 0; i < col.size(); i++) {
                                if (configBeanClass.isAssignableFrom(col.get(i).getClass())) {
                                    col.remove(col.get(i));
                                    removeCustomTokens(defaultValue, configBean, parent);
                                    return param;
                                }
                            }
                        }
                    }
                    return param;
                }
            }, parent);
        } catch (Exception e) {
            String message = localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements ");
            report.setMessage(message);
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            LOG.log(Level.INFO, DELETE_MODULE_CONFIG_FAILED_DELETING_DEPENDENT, e);
        }
    } else {
        report.setMessage(localStrings.getLocalString("delete.module.config.failed.deleting.dependant", "Failed to remove all configuration elements related to your service form domain.xml. You can use create-module-config --dryRun with your module name to see all relevant configurations and try removing the config elements "));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) List(java.util.List) Method(java.lang.reflect.Method) PropertyVetoException(java.beans.PropertyVetoException)

Aggregations

ConfigBean (org.jvnet.hk2.config.ConfigBean)28 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)21 HashMap (java.util.HashMap)18 Map (java.util.Map)15 ConfigSupport (org.jvnet.hk2.config.ConfigSupport)12 Test (org.junit.Test)11 ConfigApiTest (com.sun.enterprise.configapi.tests.ConfigApiTest)8 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)8 Property (org.jvnet.hk2.config.types.Property)8 PropertyVetoException (java.beans.PropertyVetoException)7 Method (java.lang.reflect.Method)5 ConstraintViolationException (javax.validation.ConstraintViolationException)5 Dom (org.jvnet.hk2.config.Dom)5 Cluster (com.sun.enterprise.config.serverbeans.Cluster)4 Domain (com.sun.enterprise.config.serverbeans.Domain)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)4 MultiException (org.glassfish.hk2.api.MultiException)4