Search in sources :

Example 1 with GlassFishConfigBean

use of org.glassfish.config.support.GlassFishConfigBean in project Payara by payara.

the class ConfigModularityUtils method getCurrentConfigBeanForDefaultValue.

public <T extends ConfigBeanProxy> T getCurrentConfigBeanForDefaultValue(ConfigBeanDefaultValue defaultValue) throws InvocationTargetException, IllegalAccessException {
    // TODO make this method target aware!
    Class parentClass = getOwningClassForLocation(defaultValue.getLocation());
    Class configBeanClass = getClassForFullName(defaultValue.getConfigBeanClassName());
    Method m = findSuitableCollectionGetter(parentClass, configBeanClass);
    if (m != null) {
        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) {
                // by default, people get the translated view.
                return new GlassFishConfigBean(serviceLocator, this, dom, configModel, xmlStreamReader);
            }
        };
        ConfigBeanProxy parent = getOwningObject(defaultValue.getLocation());
        ConfigurationPopulator populator = new ConfigurationPopulator(defaultValue.getXmlConfiguration(), doc, parent);
        populator.run(configParser);
        ConfigBeanProxy configBean = doc.getRoot().createProxy(configBeanClass);
        Collection col = (Collection) m.invoke(parent);
        return (T) getConfigBeanFromCollection(col, configBean, configBeanClass);
    }
    return null;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigModel(org.jvnet.hk2.config.ConfigModel) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) GlassFishConfigBean(org.glassfish.config.support.GlassFishConfigBean) ConfigurationPopulator(com.sun.enterprise.config.modularity.parser.ConfigurationPopulator) ConfigParser(org.jvnet.hk2.config.ConfigParser) Collection(java.util.Collection) Method(java.lang.reflect.Method) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 2 with GlassFishConfigBean

use of org.glassfish.config.support.GlassFishConfigBean 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 3 with GlassFishConfigBean

use of org.glassfish.config.support.GlassFishConfigBean in project Payara by payara.

the class DefaultConfigParser method parseContainerConfig.

@Override
public <T extends Container> T parseContainerConfig(ServiceLocator habitat, final URL configuration, Class<T> configType) throws IOException {
    // I don't use the GlassFish document here as I don't need persistence
    final DomDocument doc = new DomDocument<GlassFishConfigBean>(habitat) {

        @Override
        public Dom make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
            // by default, people get the translated view.
            return new GlassFishConfigBean(habitat, this, dom, configModel, xmlStreamReader);
        }
    };
    // add the new container configuration to the server config
    final T container = doc.getRoot().createProxy(configType);
    try {
        ConfigSupport.apply(new SingleConfigCode<Config>() {

            @Override
            public Object run(Config config) throws PropertyVetoException, TransactionFailure {
                config.getContainers().add(container);
                return null;
            }
        }, config);
    } catch (TransactionFailure e) {
        logger.log(Level.SEVERE, KernelLoggerInfo.exceptionAddContainer, e);
    }
    return container;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PropertyVetoException(java.beans.PropertyVetoException) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigModel(org.jvnet.hk2.config.ConfigModel) GlassFishConfigBean(org.glassfish.config.support.GlassFishConfigBean) Config(com.sun.enterprise.config.serverbeans.Config) DomDocument(org.jvnet.hk2.config.DomDocument)

Aggregations

XMLStreamReader (javax.xml.stream.XMLStreamReader)3 GlassFishConfigBean (org.glassfish.config.support.GlassFishConfigBean)3 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)3 ConfigModel (org.jvnet.hk2.config.ConfigModel)3 DomDocument (org.jvnet.hk2.config.DomDocument)3 PropertyVetoException (java.beans.PropertyVetoException)2 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)2 ConfigParser (org.jvnet.hk2.config.ConfigParser)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 ConfigBeanDefaultValue (com.sun.enterprise.config.modularity.customization.ConfigBeanDefaultValue)1 ConfigurationPopulator (com.sun.enterprise.config.modularity.parser.ConfigurationPopulator)1 Config (com.sun.enterprise.config.serverbeans.Config)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1