use of org.jvnet.hk2.config.ConfigParser 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.jvnet.hk2.config.ConfigParser in project Payara by payara.
the class ConfigurationPopulator method run.
public void run(ConfigParser parser) {
try {
InputStream is = new ByteArrayInputStream(xmlContent.getBytes());
XMLStreamReader reader = XMLInputFactory.newFactory().createXMLStreamReader(is, "utf-8");
parser.parse(reader, doc, Dom.unwrap((ConfigBeanProxy) parent));
} catch (XMLStreamException e) {
LOG.log(Level.SEVERE, ConfigApiLoggerInfo.DEFAULT_CFG_READ_FAILED, e);
}
}
use of org.jvnet.hk2.config.ConfigParser in project Payara by payara.
the class Utils method getNewHabitat.
private static synchronized ServiceLocator getNewHabitat(final ConfigApiTest test) {
final ServiceLocator sl = getNewHabitat();
final String fileName = test.getFileName();
ConfigParser configParser = new ConfigParser(sl);
long now = System.currentTimeMillis();
URL url = Utils.class.getClassLoader().getResource(fileName + ".xml");
if (url != null) {
try {
DomDocument testDocument = test.getDocument(sl);
DomDocument document = configParser.parse(url, testDocument);
ServiceLocatorUtilities.addOneConstant(sl, document);
test.decorate(sl);
} catch (Exception e) {
e.printStackTrace();
}
Logger.getAnonymousLogger().fine("time to parse domain.xml : " + String.valueOf(System.currentTimeMillis() - now));
}
return sl;
}
use of org.jvnet.hk2.config.ConfigParser in project Payara by payara.
the class ConfigTest method parseDomainXml.
// @Test
public void parseDomainXml() {
ConfigParser parser = new ConfigParser(habitat);
URL url = this.getClass().getResource("/domain.xml");
System.out.println("URL : " + url);
try {
DomDocument doc = parser.parse(url);
System.out.println("[parseDomainXml] ==> Successfully parsed");
assert (doc != null);
} catch (Exception ex) {
ex.printStackTrace();
assert (false);
}
}
use of org.jvnet.hk2.config.ConfigParser in project Payara by payara.
the class ConsolePluginService method getHelpTOC.
/**
* <p> This method returns a merged Table Of Contents for all found help
* sets for the given locale.</p>
*/
public synchronized TOC getHelpTOC(String locale) {
if (locale == null) {
// Use this as the default...
locale = "en";
}
TOC mergedTOC = helpSetMap.get(locale);
if (mergedTOC != null) {
// Already calculated...
return mergedTOC;
}
// TOC
Map<String, List<URL>> mapUrls = getResources(locale + "/help/toc.xml");
// Get our parser...
ConfigParser parser = new ConfigParser(habitat);
// Setup a new "merged" TOC...
mergedTOC = new TOC();
mergedTOC.setTOCItems(new ArrayList<TOCItem>());
mergedTOC.setVersion("2.0");
// Loop through the urls and add them all
// module id
String id = null;
// prefix (minus module id)
String prefix = "/" + locale + "/help/";
// URLs to TOC files w/i each plugin module
List<URL> urls = null;
for (Map.Entry<String, List<URL>> entry : mapUrls.entrySet()) {
id = entry.getKey();
urls = entry.getValue();
for (URL url : urls) {
DomDocument doc = parser.parse(url);
// Merge all the TOC's...
TOC toc = (TOC) doc.getRoot().get();
for (TOCItem item : toc.getTOCItems()) {
insertTOCItem(mergedTOC.getTOCItems(), item, id + prefix);
}
}
}
// FIXME: Sort?
return mergedTOC;
}
Aggregations