Search in sources :

Example 6 with CommandModel

use of org.glassfish.api.admin.CommandModel in project Payara by payara.

the class MapInjectionResolverTest method getParamValueTest.

@Test
public void getParamValueTest() {
    try {
        DummyCommand dc = new DummyCommand();
        Class<?> cl = dc.getClass();
        ParameterMap params = new ParameterMap();
        params.add("hello", "world");
        CommandModel dccm = new CommandModelImpl(dc.getClass());
        MapInjectionResolver mir = new MapInjectionResolver(dccm, params);
        AnnotatedElement ae = (AnnotatedElement) cl.getDeclaredField("hello");
        String hello = mir.getValue(dc, ae, null, String.class);
        assertEquals("hello should be world", "world", hello);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("unexpected exception");
    }
}
Also used : AnnotatedElement(java.lang.reflect.AnnotatedElement) ParameterMap(org.glassfish.api.admin.ParameterMap) CommandModel(org.glassfish.api.admin.CommandModel) Test(org.junit.Test)

Example 7 with CommandModel

use of org.glassfish.api.admin.CommandModel in project Payara by payara.

the class CommandRunnerTest method getUsageTextTest.

@Test
public void getUsageTextTest() {
    String expectedUsageText = "Usage: dummy-admin --foo=foo [--bar=false] --hello=there world ";
    DummyAdminCommand dac = new DummyAdminCommand();
    CommandModel model = new CommandModelImpl(DummyAdminCommand.class);
    String actualUsageText = cr.getUsageText(model);
    assertEquals(expectedUsageText, actualUsageText);
}
Also used : CommandModel(org.glassfish.api.admin.CommandModel) CommandModelImpl(org.glassfish.common.util.admin.CommandModelImpl) Test(org.junit.Test)

Example 8 with CommandModel

use of org.glassfish.api.admin.CommandModel in project Payara by payara.

the class Util method getMethodParameterList.

public static String getMethodParameterList(CommandModel cm, boolean withType, boolean includeOptional) {
    StringBuilder sb = new StringBuilder();
    Collection<CommandModel.ParamModel> params = cm.getParameters();
    if ((params != null) && (!params.isEmpty())) {
        String sep = "";
        for (CommandModel.ParamModel model : params) {
            Param param = model.getParam();
            boolean include = true;
            if (param.optional() && !includeOptional) {
                continue;
            }
            sb.append(sep);
            if (withType) {
                String type = model.getType().getName();
                if (model.getType().isArray()) {
                    type = model.getType().getName().substring(2);
                    type = type.substring(0, type.length() - 1) + "[]";
                } else if (type.startsWith("java.lang")) {
                    type = model.getType().getSimpleName();
                }
                sb.append(type);
            }
            sb.append(" _").append(Util.eleminateHypen(model.getName()));
            sep = ", ";
        }
    }
    return sb.toString();
}
Also used : Param(org.glassfish.api.Param) CommandModel(org.glassfish.api.admin.CommandModel)

Example 9 with CommandModel

use of org.glassfish.api.admin.CommandModel in project Payara by payara.

the class StatusGenerator method getParamMetaData.

public Collection<CommandModel.ParamModel> getParamMetaData(String commandName) {
    CommandRunner cr = serviceLocator.getService(CommandRunner.class);
    CommandModel cm = cr.getModel(commandName, RestLogging.restLogger);
    Collection<CommandModel.ParamModel> params = cm.getParameters();
    return params;
}
Also used : CommandModel(org.glassfish.api.admin.CommandModel) CommandRunner(org.glassfish.api.admin.CommandRunner)

Example 10 with CommandModel

use of org.glassfish.api.admin.CommandModel in project Payara by payara.

the class ResourceUtil method getParamMetaData.

/**
 * Constructs and returns the parameter meta-data.
 *
 * @param commandName the command associated with the resource method
 * @param commandParamsToSkip the command parameters for which not to
 * include the meta-data.
 * @param habitat the habitat
 * @param logger the logger to use
 * @return Collection the meta-data for the parameter of the resource
 * method.
 */
public static Collection<CommandModel.ParamModel> getParamMetaData(String commandName, Collection<String> commandParamsToSkip, ServiceLocator habitat) {
    CommandModel cm = habitat.<CommandRunner>getService(CommandRunner.class).getModel(commandName, RestLogging.restLogger);
    Collection<String> parameterNames = cm.getParametersNames();
    ArrayList<CommandModel.ParamModel> metaData = new ArrayList<CommandModel.ParamModel>();
    CommandModel.ParamModel paramModel;
    for (String name : parameterNames) {
        paramModel = cm.getModelFor(name);
        String parameterName = (paramModel.getParam().primary()) ? "id" : paramModel.getName();
        if (!commandParamsToSkip.contains(parameterName)) {
            metaData.add(paramModel);
        }
    }
    // print(metaData);
    return metaData;
}
Also used : ArrayList(java.util.ArrayList) CommandModel(org.glassfish.api.admin.CommandModel) CommandRunner(org.glassfish.api.admin.CommandRunner)

Aggregations

CommandModel (org.glassfish.api.admin.CommandModel)10 Param (org.glassfish.api.Param)4 CachedCommandModel (com.sun.enterprise.admin.util.CachedCommandModel)2 CommandException (org.glassfish.api.admin.CommandException)2 CommandRunner (org.glassfish.api.admin.CommandRunner)2 ParameterMap (org.glassfish.api.admin.ParameterMap)2 Test (org.junit.Test)2 Parser (com.sun.enterprise.admin.cli.Parser)1 ParamModelData (com.sun.enterprise.admin.util.CommandModelData.ParamModelData)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 SocketException (java.net.SocketException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 SSLException (javax.net.ssl.SSLException)1