Search in sources :

Example 16 with ConfigModel

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

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

the class TemplateListOfResource method getPostCommand.

/**
 * allows for remote files to be put in a tmp area and we pass the
 * local location of this file to the corresponding command instead of the content of the file
 * * Yu need to add  enctype="multipart/form-data" in the form
 * for ex:  <form action="http://localhost:4848/management/domain/applications/application" method="post" enctype="multipart/form-data">
 * then any param of type="file" will be uploaded, stored locally and the param will use the local location
 * on the server side (ie. just the path)
 */
public String getPostCommand() {
    ConfigModel.Property p = parent.model.getElement(tagName);
    if (p == null) {
        // "*"
        ConfigModel.Property childElement = parent.model.getElement("*");
        if (childElement != null) {
            ConfigModel.Node node = (ConfigModel.Node) childElement;
            ConfigModel childModel = node.getModel();
            List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, parent.document);
            for (ConfigModel subChildConfigModel : subChildConfigModels) {
                if (subChildConfigModel.getTagName().equals(tagName)) {
                    return ResourceUtil.getCommand(RestRedirect.OpType.POST, subChildConfigModel);
                }
            }
        }
    } else {
        ConfigModel.Node n = (ConfigModel.Node) p;
        String command = ResourceUtil.getCommand(RestRedirect.OpType.POST, n.getModel());
        if (command != null) {
            return command;
        }
        // last  possible case...the @Create annotation on a parent method
        Class<? extends ConfigBeanProxy> cbp = null;
        try {
            cbp = (Class<? extends ConfigBeanProxy>) parent.model.classLoaderHolder.loadClass(parent.model.targetTypeName);
        } catch (MultiException e) {
            // 
            return null;
        }
        Create create = null;
        for (Method m : cbp.getMethods()) {
            ConfigModel.Property pp = parent.model.toProperty(m);
            if ((pp != null) && (pp.xmlName.equals(tagName)) && (m.isAnnotationPresent(Create.class))) {
                create = m.getAnnotation(Create.class);
                break;
            }
        }
        if (create != null) {
            return create.value();
        }
    }
    return null;
}
Also used : ConfigModel(org.jvnet.hk2.config.ConfigModel) Create(org.glassfish.config.support.Create) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException)

Example 18 with ConfigModel

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

Example 19 with ConfigModel

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

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

Aggregations

ConfigModel (org.jvnet.hk2.config.ConfigModel)20 DomDocument (org.jvnet.hk2.config.DomDocument)8 MultiException (org.glassfish.hk2.api.MultiException)6 Dom (org.jvnet.hk2.config.Dom)6 Domain (com.sun.enterprise.config.serverbeans.Domain)5 Method (java.lang.reflect.Method)5 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)4 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 Attribute (org.jvnet.hk2.config.Attribute)3 PropertyVetoException (java.beans.PropertyVetoException)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)2