Search in sources :

Example 1 with Create

use of org.glassfish.config.support.Create 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)

Aggregations

Method (java.lang.reflect.Method)1 Create (org.glassfish.config.support.Create)1 MultiException (org.glassfish.hk2.api.MultiException)1 ConfigModel (org.jvnet.hk2.config.ConfigModel)1