Search in sources :

Example 36 with Dom

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

the class VerifyDomainXmlCommand method executeCommand.

/**
 */
@Override
protected int executeCommand() throws CommandException, CommandValidationException {
    File domainXMLFile = getDomainXml();
    logger.log(Level.FINER, "Domain XML file = {0}", domainXMLFile);
    try {
        // get the list of JAR files from the modules directory
        ArrayList<URL> urls = new ArrayList<URL>();
        File idir = new File(System.getProperty(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
        File mdir = new File(idir, "modules");
        for (File f : mdir.listFiles()) {
            if (f.toString().endsWith(".jar")) {
                urls.add(f.toURI().toURL());
            }
        }
        final URL[] urlsA = urls.toArray(new URL[urls.size()]);
        ClassLoader cl = (ClassLoader) AccessController.doPrivileged(new PrivilegedAction() {

            @Override
            public Object run() {
                return new URLClassLoader(urlsA, Globals.class.getClassLoader());
            }
        });
        ModulesRegistry registry = new StaticModulesRegistry(cl);
        ServiceLocator serviceLocator = registry.createServiceLocator("default");
        ConfigParser parser = new ConfigParser(serviceLocator);
        URL domainURL = domainXMLFile.toURI().toURL();
        DomDocument doc = parser.parse(domainURL);
        Dom domDomain = doc.getRoot();
        Domain domain = domDomain.createProxy(Domain.class);
        DomainXmlVerifier validator = new DomainXmlVerifier(domain);
        if (validator.invokeConfigValidator())
            return 1;
    } catch (Exception e) {
        throw new CommandException(e);
    }
    return 0;
}
Also used : Dom(org.jvnet.hk2.config.Dom) ArrayList(java.util.ArrayList) ConfigParser(org.jvnet.hk2.config.ConfigParser) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) URL(java.net.URL) IOException(java.io.IOException) DomDocument(org.jvnet.hk2.config.DomDocument) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) PrivilegedAction(java.security.PrivilegedAction) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) StaticModulesRegistry(com.sun.enterprise.module.single.StaticModulesRegistry) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) Domain(com.sun.enterprise.config.serverbeans.Domain) File(java.io.File)

Example 37 with Dom

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

the class GlassFishDomainResource method setBaseServiceLocator.

// called when jersey is injecting the habitat...
@Context
public void setBaseServiceLocator(LocatorBridge hab) {
    Dom dom1 = Dom.unwrap(hab.getRemoteLocator().<Domain>getService(Domain.class));
    childModel = dom1.document.getRoot().model;
    entity = dom1.document.getRoot();
}
Also used : Dom(org.jvnet.hk2.config.Dom) Domain(com.sun.enterprise.config.serverbeans.Domain) Context(javax.ws.rs.core.Context)

Example 38 with Dom

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

the class PropertiesBagResource method getExistingProperties.

protected Map<String, Property> getExistingProperties() {
    Map<String, Property> properties = new HashMap<>();
    if (parent != null) {
        List<Dom> children;
        synchronized (parent) {
            children = parent.nodeElements(tagName);
        }
        for (Dom child : children) {
            Property property = child.createProxy();
            properties.put(property.getName(), property);
        }
    }
    return properties;
}
Also used : Dom(org.jvnet.hk2.config.Dom) Property(org.jvnet.hk2.config.types.Property)

Example 39 with Dom

use of org.jvnet.hk2.config.Dom 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 40 with Dom

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

the class TemplateRestResource method setBeanByKey.

/*
     * This method is called by the ASM generated code change very carefully
     */
public void setBeanByKey(List<Dom> parentList, String id, String tag) {
    this.tagName = tag;
    try {
        childID = URLDecoder.decode(id, "UTF-8");
    } catch (UnsupportedEncodingException ex) {
        childID = id;
    }
    if (parentList != null) {
        // Believe it or not, this can happen
        for (Dom c : parentList) {
            String keyAttributeName = null;
            ConfigModel model = c.model;
            if (model.key == null) {
                try {
                    for (String s : model.getAttributeNames()) {
                        // no key, by default use the name attr
                        if (s.equals("name")) {
                            keyAttributeName = s;
                        }
                    }
                    if (keyAttributeName == null) {
                        // nothing, so pick the first one
                        keyAttributeName = model.getAttributeNames().iterator().next();
                    }
                } catch (Exception e) {
                    // no attr choice fo a key!!! Error!!!
                    keyAttributeName = "ThisIsAModelBug:NoKeyAttr";
                }
            // firstone
            } else {
                keyAttributeName = model.key.substring(1, model.key.length());
            }
            String keyvalue = c.attribute(keyAttributeName.toLowerCase(Locale.US));
            if (keyvalue.equals(childID)) {
                setEntity((ConfigBean) c);
            }
        }
    }
}
Also used : Dom(org.jvnet.hk2.config.Dom) ConfigModel(org.jvnet.hk2.config.ConfigModel) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MultiException(org.glassfish.hk2.api.MultiException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Dom (org.jvnet.hk2.config.Dom)37 ConfigModel (org.jvnet.hk2.config.ConfigModel)14 Domain (com.sun.enterprise.config.serverbeans.Domain)12 DomDocument (org.jvnet.hk2.config.DomDocument)9 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)9 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)8 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)8 PropertyVetoException (java.beans.PropertyVetoException)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 MultiException (org.glassfish.hk2.api.MultiException)5 Config (com.sun.enterprise.config.serverbeans.Config)4 TreeMap (java.util.TreeMap)4 ConfigParser (org.jvnet.hk2.config.ConfigParser)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ResourcesGenerator (org.glassfish.admin.rest.generator.ResourcesGenerator)3 ExampleServiceConfiguration (fish.payara.service.example.config.ExampleServiceConfiguration)2