Search in sources :

Example 1 with ParameterMetaData

use of org.glassfish.admin.rest.provider.ParameterMetaData in project Payara by payara.

the class ResourceUtil method getMethodMetaData.

/**
 * Constructs and returns the resource method meta-data.
 *
 * @param command 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 MethodMetaData the meta-data store for the resource method.
 */
public static MethodMetaData getMethodMetaData(String command, HashMap<String, String> commandParamsToSkip, ServiceLocator habitat) {
    MethodMetaData methodMetaData = new MethodMetaData();
    if (command != null) {
        Collection<CommandModel.ParamModel> params;
        if (commandParamsToSkip == null) {
            params = getParamMetaData(command, habitat);
        } else {
            params = getParamMetaData(command, commandParamsToSkip.keySet(), habitat);
        }
        if (params != null) {
            Iterator<CommandModel.ParamModel> iterator = params.iterator();
            CommandModel.ParamModel paramModel;
            while (iterator.hasNext()) {
                paramModel = iterator.next();
                Param param = paramModel.getParam();
                ParameterMetaData parameterMetaData = getParameterMetaData(paramModel);
                String parameterName = (param.primary()) ? "id" : paramModel.getName();
                // If the Param has an alias, use it instead of the name
                String alias = param.alias();
                if (alias != null && (!alias.isEmpty())) {
                    parameterName = alias;
                }
                methodMetaData.putParameterMetaData(parameterName, parameterMetaData);
            }
        }
    }
    return methodMetaData;
}
Also used : Param(org.glassfish.api.Param) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) CommandModel(org.glassfish.api.admin.CommandModel) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Example 2 with ParameterMetaData

use of org.glassfish.admin.rest.provider.ParameterMetaData in project Payara by payara.

the class ResourceUtil method getMethodMetaData2.

public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType) {
    MethodMetaData methodMetaData = new MethodMetaData();
    List<Class<?>> interfaces = new ArrayList<Class<?>>();
    Map<String, ParameterMetaData> params = new HashMap<String, ParameterMetaData>();
    try {
        Class<? extends ConfigBeanProxy> configBeanProxy = (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
        getInterfaces(configBeanProxy, interfaces);
        Set<String> attributeNames = childModel.getAttributeNames();
        for (String attributeName : attributeNames) {
            String methodName = ResourceUtil.getAttributeMethodName(attributeName);
            // camelCase the attributeName before passing out
            attributeName = Util.eleminateHypen(attributeName);
            ParameterMetaData parameterMetaData = params.get(attributeName);
            if (parameterMetaData == null) {
                parameterMetaData = new ParameterMetaData();
                params.put(attributeName, parameterMetaData);
            }
            // Check parent interfaces
            for (int i = interfaces.size() - 1; i >= 0; i--) {
                Class<?> intf = interfaces.get(i);
                try {
                    Method method = intf.getMethod(methodName);
                    Attribute attribute = method.getAnnotation(Attribute.class);
                    if (attribute != null) {
                        ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
                        copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
                    }
                } catch (NoSuchMethodException e) {
                }
            }
            // Check ConfigBean
            try {
                Method method = configBeanProxy.getMethod(methodName);
                Attribute attribute = method.getAnnotation(Attribute.class);
                if (attribute != null) {
                    ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
                    copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
                }
            } catch (NoSuchMethodException e) {
            }
            methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
        }
    } catch (MultiException cnfe) {
        throw new RuntimeException(cnfe);
    }
    return methodMetaData;
}
Also used : HashMap(java.util.HashMap) Attribute(org.jvnet.hk2.config.Attribute) ArrayList(java.util.ArrayList) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Method(java.lang.reflect.Method) ConfigBeanProxy(org.jvnet.hk2.config.ConfigBeanProxy) MultiException(org.glassfish.hk2.api.MultiException) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Example 3 with ParameterMetaData

use of org.glassfish.admin.rest.provider.ParameterMetaData in project Payara by payara.

the class ResourceUtil method getMethodMetaData.

/**
 * Constructs and returns the resource method meta-data. This method is
 * called to get meta-data in case of update method (POST).
 *
 * @param configBeanModel the config bean associated with the resource.
 * @return MethodMetaData the meta-data store for the resource method.
 */
public static MethodMetaData getMethodMetaData(ConfigModel configBeanModel) {
    MethodMetaData methodMetaData = new MethodMetaData();
    Class<? extends ConfigBeanProxy> configBeanProxy = null;
    try {
        configBeanProxy = (Class<? extends ConfigBeanProxy>) configBeanModel.classLoaderHolder.loadClass(configBeanModel.targetTypeName);
        Set<String> attributeNames = configBeanModel.getAttributeNames();
        for (String attributeName : attributeNames) {
            String methodName = getAttributeMethodName(attributeName);
            Method method = null;
            try {
                method = configBeanProxy.getMethod(methodName);
            } catch (NoSuchMethodException e) {
                // Method not found, so let's try a brute force method if the method
                // can't be found via the method above.  For example: for
                // Ssl.getSSLInactivityTimeout(), we calculate getSslInactivityTimeout,
                // which doesn't match due to case.
                String booleanMethodName = getAttributeBooleanMethodName(attributeName);
                for (Method m : configBeanProxy.getMethods()) {
                    if (m.getName().equalsIgnoreCase(methodName) || m.getName().equalsIgnoreCase(booleanMethodName)) {
                        method = m;
                    }
                }
            }
            Attribute attribute = method.getAnnotation(Attribute.class);
            if (attribute != null) {
                ParameterMetaData parameterMetaData = getParameterMetaData(attribute);
                if (method.getAnnotation(Deprecated.class) != null) {
                    parameterMetaData.putAttribute(Constants.DEPRECATED, "true");
                }
                // camelCase the attributeName before passing out
                attributeName = eleminateHypen(attributeName);
                methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
            }
        }
    } catch (MultiException e) {
        e.printStackTrace();
    }
    return methodMetaData;
}
Also used : Attribute(org.jvnet.hk2.config.Attribute) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Method(java.lang.reflect.Method) MultiException(org.glassfish.hk2.api.MultiException) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Example 4 with ParameterMetaData

use of org.glassfish.admin.rest.provider.ParameterMetaData in project Payara by payara.

the class ResourceUtil method getParameterMetaData.

// Construct parameter meta-data from the attribute annotation
static ParameterMetaData getParameterMetaData(Attribute attribute) {
    ParameterMetaData parameterMetaData = new ParameterMetaData();
    parameterMetaData.putAttribute(Constants.TYPE, getXsdType(attribute.dataType().toString()));
    parameterMetaData.putAttribute(Constants.OPTIONAL, Boolean.toString(!attribute.required()));
    if (!(attribute.defaultValue().equals("\u0000"))) {
        parameterMetaData.putAttribute(Constants.DEFAULT_VALUE, attribute.defaultValue());
    }
    parameterMetaData.putAttribute(Constants.KEY, Boolean.toString(attribute.key()));
    return parameterMetaData;
}
Also used : ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Example 5 with ParameterMetaData

use of org.glassfish.admin.rest.provider.ParameterMetaData in project Payara by payara.

the class ResourceUtil method buildMethodMetadataMap.

public static Map buildMethodMetadataMap(MethodMetaData mmd) {
    // yuck
    Map<String, Map> map = new TreeMap<String, Map>();
    Set<String> params = mmd.parameters();
    Iterator<String> iterator = params.iterator();
    String param;
    while (iterator.hasNext()) {
        param = iterator.next();
        ParameterMetaData parameterMetaData = mmd.getParameterMetaData(param);
        map.put(param, processAttributes(parameterMetaData.attributes(), parameterMetaData));
    }
    return map;
}
Also used : TreeMap(java.util.TreeMap) Map(java.util.Map) ParameterMap(org.glassfish.api.admin.ParameterMap) HashMap(java.util.HashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) TreeMap(java.util.TreeMap) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Aggregations

ParameterMetaData (org.glassfish.admin.rest.provider.ParameterMetaData)6 MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)3 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 Param (org.glassfish.api.Param)2 MultiException (org.glassfish.hk2.api.MultiException)2 Attribute (org.jvnet.hk2.config.Attribute)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 CommandModel (org.glassfish.api.admin.CommandModel)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1 ConfigBeanProxy (org.jvnet.hk2.config.ConfigBeanProxy)1