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;
}
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);
}
}
}
}
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;
}
Aggregations