Search in sources :

Example 1 with DomDocument

use of org.jvnet.hk2.config.DomDocument in project Payara by payara.

the class ConsolePluginService method init.

/**
 *	<p> Initialize the available {@link IntegrationPoint}s.</p>
 */
protected synchronized void init() {
    if (initialized) {
        return;
    }
    initialized = true;
    // First find the parser
    if ((providers != null) && (providers.iterator().hasNext())) {
        // Get our parser...
        ConfigParser parser = new ConfigParser(habitat);
        URL url = null;
        String id = null;
        // Loop through the configs and add them all
        for (ConsoleProvider provider : providers) {
            // Read the contents from the URL
            url = provider.getConfiguration();
            if (url == null) {
                url = provider.getClass().getClassLoader().getResource(ConsoleProvider.DEFAULT_CONFIG_FILENAME);
            }
            if (url == null) {
                if (logger.isLoggable(Level.INFO)) {
                    logger.info("Unable to find " + ConsoleProvider.DEFAULT_CONFIG_FILENAME + " file for provider '" + provider.getClass().getName() + "'");
                }
                continue;
            }
            // System.out.println("Provider *"+provider+"* : url=*"+url+"*");
            DomDocument doc = parser.parse(url);
            // Get the New IntegrationPoints
            ConsoleConfig config = (ConsoleConfig) doc.getRoot().get();
            // Save the ClassLoader for later
            // System.out.println("Storing: " + config.getId() + " : " + provider.getClass().getClassLoader());
            id = config.getId();
            moduleClassLoaderMap.put(id, provider.getClass().getClassLoader());
            classLoaderModuleMap.put(provider.getClass().getClassLoader(), id);
            // Add the new IntegrationPoints
            addIntegrationPoints(config.getIntegrationPoints(), id);
        }
    }
    // Log some trace messages
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("Console Plugin Service has been Initialized!");
        if (logger.isLoggable(Level.FINEST)) {
            logger.finest(pointsByType.toString());
        }
    }
}
Also used : ConsoleConfig(org.glassfish.admingui.connector.ConsoleConfig) ConfigParser(org.jvnet.hk2.config.ConfigParser) ConsoleProvider(org.glassfish.api.admingui.ConsoleProvider) URL(java.net.URL) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 2 with DomDocument

use of org.jvnet.hk2.config.DomDocument in project Payara by payara.

the class ConsolePluginService method getHelpIndex.

/**
 *	<p> This method returns a merged Table Of Contents for all found help
 *	    sets for the given locale.</p>
 */
public synchronized Index getHelpIndex(String locale) {
    if (locale == null) {
        // Use this as the default...
        locale = "en";
    }
    Index mergedIndex = helpSetIndexMap.get(locale);
    if (mergedIndex != null) {
        // Already calculated...
        return mergedIndex;
    }
    // TOC
    Map<String, List<URL>> mapUrls = getResources(locale + "/help/index.xml");
    // Get our parser...
    ConfigParser parser = new ConfigParser(habitat);
    // Setup a new "merged" TOC...
    mergedIndex = new Index();
    mergedIndex.setIndexItems(new ArrayList<IndexItem>());
    mergedIndex.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...
            Index index = (Index) doc.getRoot().get();
            for (IndexItem item : index.getIndexItems()) {
                insertIndexItem(mergedIndex.getIndexItems(), item, id + prefix);
            }
        }
    }
    // FIXME: Sort?
    return mergedIndex;
}
Also used : ConfigParser(org.jvnet.hk2.config.ConfigParser) Index(org.glassfish.admingui.connector.Index) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) MultiMap(org.jvnet.hk2.component.MultiMap) IndexItem(org.glassfish.admingui.connector.IndexItem) URL(java.net.URL) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 3 with DomDocument

use of org.jvnet.hk2.config.DomDocument in project Payara by payara.

the class ConfigApiTest method getDocument.

@Override
public DomDocument getDocument(ServiceLocator habitat) {
    DomDocument doc = habitat.getService(GlassFishDocument.class);
    if (doc == null) {
        return new GlassFishDocument(habitat, Executors.newCachedThreadPool(new ThreadFactory() {

            public Thread newThread(Runnable r) {
                Thread t = Executors.defaultThreadFactory().newThread(r);
                t.setDaemon(true);
                return t;
            }
        }));
    }
    return doc;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) GlassFishDocument(org.glassfish.config.support.GlassFishDocument) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 4 with DomDocument

use of org.jvnet.hk2.config.DomDocument in project Payara by payara.

the class GadgetHandlers method getGadgetModule.

/**
 *	<p> This method returns a {@link GadgetModule} for the given URL.</p>
 */
public static GadgetModule getGadgetModule(URL url) {
    if (url == null) {
        return null;
    }
    // FIXME: Cache?
    // Get our parser...
    ConfigParser parser = new ConfigParser(GuiUtil.getHabitat());
    String id = null;
    // Read the document...
    DomDocument doc = parser.parse(url);
    // Get the GadgetModule
    GadgetModule module = (GadgetModule) doc.getRoot().get();
    return module;
}
Also used : GadgetModule(org.glassfish.admingui.connector.GadgetModule) ConfigParser(org.jvnet.hk2.config.ConfigParser) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 5 with DomDocument

use of org.jvnet.hk2.config.DomDocument in project Payara by payara.

the class ResourcesGeneratorBase method generateSingle.

/**
 * Generate REST resource for a single config model.
 */
@Override
public void generateSingle(ConfigModel model, DomDocument domDocument) {
    configModelVisited(model);
    // processRedirectsAnnotation(model); // TODO need to extract info from RestRedirect Annotations
    String serverConfigName = ResourceUtil.getUnqualifiedTypeName(model.targetTypeName);
    String beanName = getBeanName(serverConfigName);
    String className = getClassName(beanName);
    if (alreadyGenerated(className)) {
        return;
    }
    String baseClassName = "TemplateRestResource";
    String resourcePath = null;
    if (beanName.equals("Domain")) {
        baseClassName = "org.glassfish.admin.rest.resources.GlassFishDomainResource";
        resourcePath = "domain";
    }
    ClassWriter classWriter = getClassWriter(className, baseClassName, resourcePath);
    if (classWriter != null) {
        generateCommandResources(beanName, classWriter);
        generateGetDeleteCommandMethod(beanName, classWriter);
        generateCustomResourceMapping(beanName, classWriter);
        for (String elementName : model.getElementNames()) {
            ConfigModel.Property childElement = model.getElement(elementName);
            if (elementName.equals("*")) {
                ConfigModel.Node node = (ConfigModel.Node) childElement;
                ConfigModel childModel = node.getModel();
                List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, domDocument);
                for (ConfigModel subChildConfigModel : subChildConfigModels) {
                    if (ResourceUtil.isOnlyATag(childModel) || ResourceUtil.isOnlyATag(subChildConfigModel) || subChildConfigModel.getAttributeNames().isEmpty() || hasSingletonAnnotation(subChildConfigModel)) {
                        String childResourceClassName = getClassName(ResourceUtil.getUnqualifiedTypeName(subChildConfigModel.targetTypeName));
                        String childPath = subChildConfigModel.getTagName();
                        classWriter.createGetChildResource(childPath, childResourceClassName);
                        generateSingle(subChildConfigModel, domDocument);
                    } else {
                        processNonLeafChildConfigModel(subChildConfigModel, childElement, domDocument, classWriter);
                    }
                }
            } else if (childElement.isLeaf()) {
                if (childElement.isCollection()) {
                    // handle the CollectionLeaf config objects.
                    // JVM Options is an example of CollectionLeaf object.
                    String childResourceBeanName = getBeanName(elementName);
                    String childResourceClassName = getClassName(childResourceBeanName);
                    classWriter.createGetChildResource(elementName, childResourceClassName);
                    // create resource class
                    generateCollectionLeafResource(childResourceBeanName);
                } else {
                    String childResourceBeanName = getBeanName(elementName);
                    String childResourceClassName = getClassName(childResourceBeanName);
                    classWriter.createGetChildResource(elementName, childResourceClassName);
                    // create resource class
                    generateLeafResource(childResourceBeanName);
                }
            } else {
                // => !childElement.isLeaf()
                processNonLeafChildElement(elementName, childElement, domDocument, classWriter);
            }
        }
        classWriter.done();
    }
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel)

Aggregations

DomDocument (org.jvnet.hk2.config.DomDocument)25 ConfigModel (org.jvnet.hk2.config.ConfigModel)12 ConfigParser (org.jvnet.hk2.config.ConfigParser)12 URL (java.net.URL)8 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)7 IOException (java.io.IOException)6 ThreadFactory (java.util.concurrent.ThreadFactory)6 GlassFishDocument (org.glassfish.config.support.GlassFishDocument)6 Domain (com.sun.enterprise.config.serverbeans.Domain)5 Dom (org.jvnet.hk2.config.Dom)5 PropertyVetoException (java.beans.PropertyVetoException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)3 GET (javax.ws.rs.GET)3 Produces (javax.ws.rs.Produces)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 ResourcesGenerator (org.glassfish.admin.rest.generator.ResourcesGenerator)3 GlassFishConfigBean (org.glassfish.config.support.GlassFishConfigBean)3 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)3 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)3