Search in sources :

Example 26 with DomDocument

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

the class StatusGenerator method getHtml.

@GET
@Produces({ MediaType.TEXT_HTML })
public String getHtml() {
    try {
        Domain entity = serviceLocator.getService(Domain.class);
        Dom dom = Dom.unwrap(entity);
        DomDocument document = dom.document;
        ConfigModel rootModel = dom.document.getRoot().model;
        ResourcesGenerator resourcesGenerator = new NOOPResourcesGenerator(serviceLocator);
        resourcesGenerator.generateSingle(rootModel, document);
        resourcesGenerator.endGeneration();
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    }
    status.append("<h4>All Commands used in REST Admin</h4>\n<ul>\n");
    for (String ss : commandsUsed) {
        status.append("<li>").append(ss).append("</li>\n");
    }
    listOfCommands();
    for (String ss : commandsUsed) {
        allCommands.remove(ss);
    }
    status.append("</ul>\n<hr/>\n").append("<h4>Missing Commands not used in REST Admin</h4>\n<ul>\n");
    for (String ss : allCommands) {
        if (hasTargetParam(ss)) {
            status.append("<li>").append(ss).append("          has a target param.</li>\n");
        } else {
            status.append("<li>").append(ss).append("</li>\n");
        }
    }
    status.append("</ul>\n<hr/>\n").append("<h4>REST-REDIRECT Commands defined on ConfigBeans</h4>\n<ul>\n");
    for (String ss : restRedirectCommands) {
        status.append("<li>").append(ss).append("</li>\n");
    }
    status.append("</ul>\n<hr/>\n").append("<h4>Commands to Resources Mapping Usage in REST Admin</h4>\n").append("<table border=\"1\" style=\"border-collapse: collapse\">\n").append("<tr><th>Command</th><th>Target</th><th>Resource</th></tr>\n");
    for (String ss : commandsToResources.keySet()) {
        status.append("<tr><td>").append(ss).append("</td><td>").append(hasTargetParam(ss) ? "target" : "").append("</td><td>").append(commandsToResources.get(ss)).append("</td></tr>\n");
    }
    status.append("</table>\n<hr/>\n").append("<h4>Resources with Delete Commands in REST Admin (not counting RESTREDIRECT)</h4>\n").append("<table border=\"1\" style=\"border-collapse: collapse\">\n").append("<tr><th>Resource</th><th>Delete Command</th></tr>\n");
    for (String ss : resourcesToDeleteCommands.keySet()) {
        status.append("<tr><td>").append(ss).append("</td><td>").append(resourcesToDeleteCommands.get(ss)).append("</td></tr>\n");
    }
    status.append("</table>");
    FileOutputStream f = null;
    try {
        f = new FileOutputStream(System.getProperty("user.home") + "/GlassFishI18NData.properties");
        propsI18N.store(f, "");
    } catch (Exception ex) {
        RestLogging.restLogger.log(Level.SEVERE, null, ex);
    } finally {
        if (f != null) {
            try {
                f.close();
            } catch (IOException ex) {
                RestLogging.restLogger.log(Level.SEVERE, null, ex);
            }
        }
    }
    return status.toString();
}
Also used : Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) FileOutputStream(java.io.FileOutputStream) ResourcesGenerator(org.glassfish.admin.rest.generator.ResourcesGenerator) IOException(java.io.IOException) Domain(com.sun.enterprise.config.serverbeans.Domain) IOException(java.io.IOException) MultiException(org.glassfish.hk2.api.MultiException) DomDocument(org.jvnet.hk2.config.DomDocument) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 27 with DomDocument

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

the class ResourceUtil method getRealChildConfigModels.

public static List<ConfigModel> getRealChildConfigModels(ConfigModel childModel, DomDocument domDocument) {
    List<ConfigModel> retlist = new ArrayList<ConfigModel>();
    try {
        Class<?> subType = childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
        List<ConfigModel> list = domDocument.getAllModelsImplementing(subType);
        if (list != null) {
            for (ConfigModel el : list) {
                if (isOnlyATag(el)) {
                    // this is just a tag element
                    retlist.addAll(getRealChildConfigModels(el, domDocument));
                } else {
                    retlist.add(el);
                }
            }
        } else {
            // https://glassfish.dev.java.net/issues/show_bug.cgi?id=12654
            if (!isOnlyATag(childModel)) {
                // this is just a tag element
                retlist.add(childModel);
            }
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
    return retlist;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) ArrayList(java.util.ArrayList)

Example 28 with DomDocument

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

the class ConfigBeanJMXSupport method getTypesImplementing.

/**
 * works only for @Configured types
 */
public static Class[] getTypesImplementing(final Class<?> clazz) {
    final DomDocument domDoc = new DomDocument(InjectedValues.getInstance().getHabitat());
    try {
        final List<ConfigModel> models = domDoc.getAllModelsImplementing(clazz);
        final Class[] interfaces = new Class[models == null ? 0 : models.size()];
        if (models != null) {
            int i = 0;
            for (final ConfigModel model : models) {
                final String classname = model.targetTypeName;
                final Class<?> intf = model.classLoaderHolder.loadClass(classname);
                interfaces[i] = intf;
                // System.out.println( "Loaded: " + intf + " with tagName of " + model.getTagName() );
                ++i;
            }
        }
        return interfaces;
    } catch (final Exception e) {
        AMXLoggerInfo.getLogger().log(Level.INFO, AMXLoggerInfo.cantGetTypesImplementing, new Object[] { clazz, e.getLocalizedMessage() });
        throw new RuntimeException(e);
    }
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) DomDocument(org.jvnet.hk2.config.DomDocument)

Example 29 with DomDocument

use of org.jvnet.hk2.config.DomDocument 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)

Example 30 with DomDocument

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

the class ResourcesGeneratorBase method processNonLeafChildElement.

private void processNonLeafChildElement(String elementName, ConfigModel.Property childElement, DomDocument domDocument, ClassWriter classWriter) {
    ConfigModel.Node node = (ConfigModel.Node) childElement;
    ConfigModel childModel = node.getModel();
    String beanName = ResourceUtil.getUnqualifiedTypeName(childModel.targetTypeName);
    if (beanName.equals("Property")) {
        classWriter.createGetChildResource("property", "PropertiesBagResource");
    } else if (beanName.equals("MonitoredAttribute")) {
        classWriter.createGetChildResource("monitored-attribute", "MonitoredAttributeBagResource");
    } else {
        String childResourceClassName = getClassName(beanName);
        if (childElement.isCollection()) {
            childResourceClassName = "List" + childResourceClassName;
        }
        classWriter.createGetChildResource(/*
                     * childModel.getTagName()
                     */
        elementName, childResourceClassName);
    }
    if (childElement.isCollection()) {
        generateList(childModel, domDocument);
    } else {
        generateSingle(childModel, domDocument);
    }
}
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