Search in sources :

Example 1 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class AbstractConfigModularityCommand method getAccessChecksForDefaultValue.

protected Collection<AccessRequired.AccessCheck> getAccessChecksForDefaultValue(List<ConfigBeanDefaultValue> values, String target, List<String> actions) {
    Collection<AccessRequired.AccessCheck> checks = new ArrayList<AccessRequired.AccessCheck>();
    for (ConfigBeanDefaultValue val : values) {
        String location = val.getLocation();
        for (String s : actions) {
            AccessRequired.AccessCheck check = new AccessRequired.AccessCheck(configModularityUtils.getOwningObject(location), s, true);
            checks.add(check);
        }
    }
    return checks;
}
Also used : AccessRequired(org.glassfish.api.admin.AccessRequired) ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) ArrayList(java.util.ArrayList)

Example 2 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class DeleteModuleConfigCommand method execute.

@Override
public void execute(AdminCommandContext context) {
    report = context.getActionReport();
    if (target != null) {
        Config newConfig = getConfigForName(target, serviceLocator, domain);
        if (newConfig != null) {
            config = newConfig;
        }
        if (config == null) {
            report.setMessage(localStrings.getLocalString("delete.module.config.target.name.invalid", "The target name specified is invalid. Please double check the target name and try again."));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    }
    if (serviceName == null) {
        report.setMessage(localStrings.getLocalString("delete.module.config.service.name.is.required", "The service name is required, please specify which service you want to delete its default configuration."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    final String className = configModularityUtils.convertConfigElementNameToClassName(serviceName);
    Class configBeanType = configModularityUtils.getClassFor(serviceName);
    if (configBeanType == null) {
        String msg = localStrings.getLocalString("delete.module.config.not.such.a.service.found", "Your service name does not match any service installed on this domain.");
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setMessage(msg);
        return;
    }
    if (configModularityUtils.hasCustomConfig(configBeanType)) {
        List<ConfigBeanDefaultValue> defaults = configModularityUtils.getDefaultConfigurations(configBeanType, configModularityUtils.getRuntimeTypePrefix(serverenv.getStartupContext()));
        deleteDependentConfigElements(defaults);
    } else {
        deleteTopLevelExtensionByType(config, className, configBeanType);
    }
}
Also used : ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) Config(com.sun.enterprise.config.serverbeans.Config)

Example 3 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class ConfigurationParser method parseAndSetConfigBean.

/**
 * @param <T> the ConfigBeanProxy type we are looking for
 */
public <T extends ConfigBeanProxy> void parseAndSetConfigBean(List<ConfigBeanDefaultValue> values) {
    ConfigParser configParser = new ConfigParser(serviceLocator);
    // I don't use the GlassFish document here as I don't need persistence
    final DomDocument doc = new DomDocument<GlassFishConfigBean>(serviceLocator) {

        @Override
        public Dom make(final ServiceLocator serviceLocator, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
            return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
        }
    };
    // the solution is to put the loop into the apply method...  But it would be some fine amount of work
    for (final ConfigBeanDefaultValue configBeanDefaultValue : values) {
        final ConfigBeanProxy parent = configModularityUtils.getOwningObject(configBeanDefaultValue.getLocation());
        if (parent == null)
            continue;
        ConfigurationPopulator populator = null;
        if (replaceSystemProperties)
            try {
                populator = new ConfigurationPopulator(configModularityUtils.replacePropertiesWithCurrentValue(configBeanDefaultValue.getXmlConfiguration(), configBeanDefaultValue), doc, parent);
            } catch (Exception e) {
                LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
            }
        else {
            // Check that parent is not null!
            populator = new ConfigurationPopulator(configBeanDefaultValue.getXmlConfiguration(), doc, parent);
        }
        populator.run(configParser);
        synchronized (configModularityUtils) {
            boolean oldValue = configModularityUtils.isIgnorePersisting();
            try {
                Class configBeanClass = configModularityUtils.getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
                final ConfigBeanProxy pr = doc.getRoot().createProxy(configBeanClass);
                configModularityUtils.setIgnorePersisting(true);
                ConfigSupport.apply(new SingleConfigCode<ConfigBeanProxy>() {

                    public Object run(ConfigBeanProxy param) throws PropertyVetoException, TransactionFailure {
                        configModularityUtils.setConfigBean(pr, configBeanDefaultValue, param);
                        return param;
                    }
                }, parent);
            } catch (TransactionFailure e) {
                LOG.log(Level.SEVERE, ConfigApiLoggerInfo.CFG_EXT_ADD_FAILED, e);
            } finally {
                configModularityUtils.setIgnorePersisting(oldValue);
            }
        }
    }
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigParser(org.jvnet.hk2.config.ConfigParser) PropertyVetoException(java.beans.PropertyVetoException) DomDocument(org.jvnet.hk2.config.DomDocument) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PropertyVetoException(java.beans.PropertyVetoException) ConfigModel(org.jvnet.hk2.config.ConfigModel) ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) GlassFishConfigBean(org.glassfish.config.support.GlassFishConfigBean)

Example 4 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class GetActiveConfigCommand method getCompleteConfiguration.

private String getCompleteConfiguration(List<ConfigBeanDefaultValue> defaults) throws InvocationTargetException, IllegalAccessException {
    StringBuilder builder = new StringBuilder();
    for (ConfigBeanDefaultValue value : defaults) {
        builder.append(localStrings.getLocalString("at.location", "At Location: "));
        builder.append(replaceExpressionsWithValues(value.getLocation()));
        builder.append(LINE_SEPARATOR);
        String substituted = configModularityUtils.replacePropertiesWithCurrentValue(getDependentConfigElement(value), value);
        builder.append(substituted);
        builder.append(LINE_SEPARATOR);
    }
    builder.deleteCharAt(builder.length() - 1);
    return builder.toString();
}
Also used : ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue)

Example 5 with ConfigBeanDefaultValue

use of com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue in project Payara by payara.

the class ConfigModularityUtils method getDefaultConfigurations.

/**
 * If exists, locate and return a URL to the configuration snippet for the given config bean class.
 *
 * @param configBeanClass the config bean type we want to check for its configuration snippet
 * @return A url to the file or null of not exists
 */
public List<ConfigBeanDefaultValue> getDefaultConfigurations(Class configBeanClass, String runtimeType) {
    // Determine if it is DAS or instance
    CustomConfiguration c = (CustomConfiguration) configBeanClass.getAnnotation(CustomConfiguration.class);
    List<ConfigBeanDefaultValue> defaults = Collections.emptyList();
    if (c.usesOnTheFlyConfigGeneration()) {
        Method m = getGetDefaultValuesMethod(configBeanClass);
        if (m != null) {
            try {
                defaults = (List<ConfigBeanDefaultValue>) m.invoke(null, runtimeType);
            } catch (Exception e) {
                LogHelper.log(LOG, Level.INFO, cannotGetDefaultConfig, e, configBeanClass.getName());
            }
        }
    } else {
        // TODO properly handle the exceptions
        LocalStringManager localStrings = new LocalStringManagerImpl(configBeanClass);
        ModuleXMLConfigurationFileParser parser = new ModuleXMLConfigurationFileParser(localStrings);
        try {
            defaults = parser.parseServiceConfiguration(getConfigurationFileUrl(configBeanClass, c.baseConfigurationFileName(), runtimeType).openStream());
        } catch (XMLStreamException e) {
            LOG.log(Level.SEVERE, cannotParseDefaultDefaultConfig, e);
        } catch (IOException e) {
            LOG.log(Level.SEVERE, cannotParseDefaultDefaultConfig, e);
        }
    }
    return defaults;
}
Also used : LocalStringManagerImpl(com.sun.enterprise.util.LocalStringManagerImpl) ConfigBeanDefaultValue(com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue) XMLStreamException(javax.xml.stream.XMLStreamException) ModuleXMLConfigurationFileParser(com.sun.enterprise.config.modularity.parser.ModuleXMLConfigurationFileParser) LocalStringManager(com.sun.enterprise.util.LocalStringManager) CustomConfiguration(com.sun.enterprise.config.modularity.annotation.CustomConfiguration) Method(java.lang.reflect.Method) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) XMLStreamException(javax.xml.stream.XMLStreamException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException)

Aggregations

ConfigBeanDefaultValue (com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue)8 PropertyVetoException (java.beans.PropertyVetoException)2 ArrayList (java.util.ArrayList)2 CustomConfiguration (com.sun.enterprise.config.modularity.annotation.CustomConfiguration)1 ConfigCustomizationToken (com.sun.enterprise.config.modularity.customization.ConfigCustomizationToken)1 FileTypeDetails (com.sun.enterprise.config.modularity.customization.FileTypeDetails)1 PortTypeDetails (com.sun.enterprise.config.modularity.customization.PortTypeDetails)1 TokenTypeDetails (com.sun.enterprise.config.modularity.customization.TokenTypeDetails)1 ModuleXMLConfigurationFileParser (com.sun.enterprise.config.modularity.parser.ModuleXMLConfigurationFileParser)1 Config (com.sun.enterprise.config.serverbeans.Config)1 StartupContext (com.sun.enterprise.module.bootstrap.StartupContext)1 LocalStringManager (com.sun.enterprise.util.LocalStringManager)1 LocalStringManagerImpl (com.sun.enterprise.util.LocalStringManagerImpl)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1