Search in sources :

Example 6 with ConfigParser

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);
            }
        }
    }
}
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 7 with ConfigParser

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);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 8 with ConfigParser

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;
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ConfigParser(org.jvnet.hk2.config.ConfigParser) URL(java.net.URL) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 9 with ConfigParser

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);
    }
}
Also used : ConfigParser(org.jvnet.hk2.config.ConfigParser) URL(java.net.URL) PropertyVetoException(java.beans.PropertyVetoException) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 10 with ConfigParser

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;
}
Also used : TOCItem(org.glassfish.admingui.connector.TOCItem) TOC(org.glassfish.admingui.connector.TOC) ConfigParser(org.jvnet.hk2.config.ConfigParser) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) MultiMap(org.jvnet.hk2.component.MultiMap) URL(java.net.URL) DomDocument(org.jvnet.hk2.config.DomDocument)

Aggregations

ConfigParser (org.jvnet.hk2.config.ConfigParser)12 DomDocument (org.jvnet.hk2.config.DomDocument)12 URL (java.net.URL)8 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)6 IOException (java.io.IOException)5 PropertyVetoException (java.beans.PropertyVetoException)3 ArrayList (java.util.ArrayList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 LogRecord (java.util.logging.LogRecord)2 GlassFishConfigBean (org.glassfish.config.support.GlassFishConfigBean)2 MultiMap (org.jvnet.hk2.component.MultiMap)2 ConfigModel (org.jvnet.hk2.config.ConfigModel)2