Search in sources :

Example 1 with SystemPropertyBag

use of com.sun.enterprise.config.serverbeans.SystemPropertyBag in project Payara by payara.

the class CreateSystemProperties method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    String sysPropName = "";
    try {
        for (final Object key : properties.keySet()) {
            final String propName = (String) key;
            sysPropName = propName;
            // value of an existing property
            try {
                TranslatedConfigView.doSubstitution.set(Boolean.FALSE);
                if (spb.containsProperty(sysPropName) && spb.getSystemProperty(sysPropName).getValue().equals(properties.getProperty(propName))) {
                    continue;
                }
            } finally {
                TranslatedConfigView.doSubstitution.set(Boolean.TRUE);
            }
            ConfigSupport.apply(new SingleConfigCode<SystemPropertyBag>() {

                @Override
                public Object run(SystemPropertyBag param) throws PropertyVetoException, TransactionFailure {
                    // update existing system property
                    for (SystemProperty sysProperty : param.getSystemProperty()) {
                        if (sysProperty.getName().equals(propName)) {
                            Transaction t = Transaction.getTransaction(param);
                            sysProperty = t.enroll(sysProperty);
                            sysProperty.setValue(properties.getProperty(propName));
                            return sysProperty;
                        }
                    }
                    // create system-property
                    SystemProperty newSysProp = param.createChild(SystemProperty.class);
                    newSysProp.setName(propName);
                    newSysProp.setValue(properties.getProperty(propName));
                    param.getSystemProperty().add(newSysProp);
                    return newSysProp;
                }
            }, spb);
            report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("create.system.properties.failed", "System property {0} creation failed", sysPropName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    } catch (Exception e) {
        report.setMessage(localStrings.getLocalString("create.system.properties.failed", "System property {0} creation failed", sysPropName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) Transaction(org.jvnet.hk2.config.Transaction) SystemPropertyBag(com.sun.enterprise.config.serverbeans.SystemPropertyBag) ActionReport(org.glassfish.api.ActionReport) SystemProperty(com.sun.enterprise.config.serverbeans.SystemProperty) PropertyVetoException(java.beans.PropertyVetoException)

Example 2 with SystemPropertyBag

use of com.sun.enterprise.config.serverbeans.SystemPropertyBag in project Payara by payara.

the class DeleteModuleConfigCommand method removeCustomTokens.

private static <T extends ConfigBeanProxy> boolean removeCustomTokens(final ConfigBeanDefaultValue configBeanDefaultValue, T finalConfigBean, ConfigBeanProxy parent) throws TransactionFailure, PropertyVetoException {
    if (parent instanceof SystemPropertyBag) {
        removeSystemPropertyForTokens(configBeanDefaultValue.getCustomizationTokens(), (SystemPropertyBag) parent);
        return true;
    } else {
        ConfigBeanProxy curParent = finalConfigBean;
        while (!(curParent instanceof SystemPropertyBag)) {
            curParent = curParent.getParent();
        }
        if (!configBeanDefaultValue.getCustomizationTokens().isEmpty()) {
            final SystemPropertyBag bag = (SystemPropertyBag) curParent;
            final List<ConfigCustomizationToken> tokens = configBeanDefaultValue.getCustomizationTokens();
            removeSystemPropertyForTokens(tokens, bag);
            return true;
        }
        return false;
    }
}
Also used : ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCustomizationToken(com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken) SystemPropertyBag(com.sun.enterprise.config.serverbeans.SystemPropertyBag)

Example 3 with SystemPropertyBag

use of com.sun.enterprise.config.serverbeans.SystemPropertyBag in project Payara by payara.

the class ConfigModularityUtils method applyCustomTokens.

public synchronized <T extends ConfigBeanProxy> void applyCustomTokens(final ConfigBeanDefaultValue configBeanDefaultValue, T finalConfigBean, ConfigBeanProxy parent) throws TransactionFailure, PropertyVetoException {
    // then that is the freaking parent, get it and set the SystemProperty :D
    if (parent instanceof SystemPropertyBag) {
        addSystemPropertyForToken(configBeanDefaultValue.getCustomizationTokens(), (SystemPropertyBag) parent);
    } else {
        ConfigBeanProxy curParent = finalConfigBean;
        while (!(curParent instanceof SystemPropertyBag)) {
            curParent = curParent.getParent();
        }
        if (configBeanDefaultValue.getCustomizationTokens().size() != 0) {
            final boolean oldIP = isIgnorePersisting();
            try {
                setIgnorePersisting(true);
                final SystemPropertyBag bag = (SystemPropertyBag) curParent;
                final List<ConfigCustomizationToken> tokens = configBeanDefaultValue.getCustomizationTokens();
                ConfigSupport.apply(new SingleConfigCode<SystemPropertyBag>() {

                    public Object run(SystemPropertyBag param) throws PropertyVetoException, TransactionFailure {
                        addSystemPropertyForToken(tokens, bag);
                        return param;
                    }
                }, bag);
            } finally {
                setIgnorePersisting(oldIP);
            }
        }
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) ConfigCustomizationToken(com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken) SystemPropertyBag(com.sun.enterprise.config.serverbeans.SystemPropertyBag)

Example 4 with SystemPropertyBag

use of com.sun.enterprise.config.serverbeans.SystemPropertyBag in project Payara by payara.

the class CLIUtil method chooseTarget.

static SystemPropertyBag chooseTarget(final Domain domain, final String target) {
    SystemPropertyBag spb = null;
    Property domainProp = domain.getProperty("administrative.domain.name");
    String domainName = domainProp.getValue();
    if ("domain".equals(target) || target.equals(domainName)) {
        spb = domain;
    } else {
        spb = domain.getConfigNamed(target);
        if (spb == null) {
            spb = domain.getClusterNamed(target);
        }
        if (spb == null) {
            spb = domain.getServerNamed(target);
        }
    }
    return spb;
}
Also used : SystemPropertyBag(com.sun.enterprise.config.serverbeans.SystemPropertyBag) Property(org.jvnet.hk2.config.types.Property)

Aggregations

SystemPropertyBag (com.sun.enterprise.config.serverbeans.SystemPropertyBag)4 ConfigCustomizationToken (com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken)2 PropertyVetoException (java.beans.PropertyVetoException)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 SystemProperty (com.sun.enterprise.config.serverbeans.SystemProperty)1 ActionReport (org.glassfish.api.ActionReport)1 Transaction (org.jvnet.hk2.config.Transaction)1 Property (org.jvnet.hk2.config.types.Property)1