org.glassfish.admin.rest
Class ResourceUtil

java.lang.Object
  extended by org.glassfish.admin.rest.ResourceUtil

public class ResourceUtil
extends java.lang.Object

Resource utilities class. Used by resource templates, TemplateListOfResource and TemplateRestResource

Author:
Rajeshwar Patil

Method Summary
static void addMethodMetaData(ActionReport ar, java.util.Map<java.lang.String,MethodMetaData> mmd)
           
static void addQueryString(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> qs, java.util.Map<java.lang.String,java.lang.String> data)
          This method takes any query string parameters and adds them to the specified map.
static void addQueryString(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> qs, java.util.Properties data)
           
static void adjustParameters(java.util.Map<java.lang.String,java.lang.String> data)
          Adjust the input parameters.
static AdminAccessController.Access authenticateViaAdminRealm(org.jvnet.hk2.component.Habitat habitat, com.sun.grizzly.tcp.http11.GrizzlyRequest req)
          Authenticate the given req against admin realm.
static AdminAccessController.Access authenticateViaAdminRealm(org.jvnet.hk2.component.Habitat habitat, com.sun.grizzly.tcp.http11.GrizzlyRequest req, java.lang.String remoteHost)
          Authenticate the given req as originated from given remoteHost against admin realm.
static java.util.Map buildMethodMetadataMap(MethodMetaData mmd)
           
static boolean canShowDeprecatedItems(org.jvnet.hk2.component.Habitat habitat)
           
static boolean commandIsPresent(org.jvnet.hk2.component.Habitat habitat, java.lang.String commandName)
           
static java.lang.String convertToXMLName(java.lang.String name)
           
protected static void copyParameterMetaDataAttribute(ParameterMetaData from, ParameterMetaData to, java.lang.String key)
           
static void defineDefaultParameters(java.util.Map<java.lang.String,java.lang.String> data)
          Adjust the input parameters.
static ActionReportResult getActionReportResult(ActionReport.ExitCode status, java.lang.String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo)
           
static ActionReportResult getActionReportResult(ActionReport parentActionReport, java.lang.String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo)
           
static java.lang.String getCommand(RestRedirect.OpType type, org.jvnet.hk2.config.ConfigModel model)
          Returns the name of the command associated with this resource,if any, for the given operation.
static java.util.List<java.util.Map<java.lang.String,java.lang.String>> getCommandLinks(java.lang.String[][] commandResourcesPaths)
           
static javax.ws.rs.core.Response getDeleteResponse(int status, java.lang.String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo, org.jvnet.hk2.component.Habitat habitat)
          special case for the delete operation: we need to give back the URI of the parent since the resource we are on is deleted
protected static void getInterfaces(java.lang.Class<?> clazz, java.util.List<java.lang.Class<?>> interfaces)
           
static MethodMetaData getMethodMetaData(org.jvnet.hk2.config.ConfigModel configBeanModel)
          Constructs and returns the resource method meta-data.
static MethodMetaData getMethodMetaData(java.lang.String command, org.jvnet.hk2.component.Habitat habitat, java.util.logging.Logger logger)
          Constructs and returns the resource method meta-data.
static MethodMetaData getMethodMetaData(java.lang.String command, java.util.HashMap<java.lang.String,java.lang.String> commandParamsToSkip, org.jvnet.hk2.component.Habitat habitat, java.util.logging.Logger logger)
          Constructs and returns the resource method meta-data.
static MethodMetaData getMethodMetaData2(org.jvnet.hk2.config.Dom parent, org.jvnet.hk2.config.ConfigModel childModel, int parameterType)
           
static java.util.Collection<CommandModel.ParamModel> getParamMetaData(java.lang.String commandName, java.util.Collection<java.lang.String> commandParamsToSkip, org.jvnet.hk2.component.Habitat habitat, java.util.logging.Logger logger)
          Constructs and returns the parameter meta-data.
static java.util.Collection<CommandModel.ParamModel> getParamMetaData(java.lang.String commandName, org.jvnet.hk2.component.Habitat habitat, java.util.logging.Logger logger)
          Constructs and returns the parameter meta-data.
static java.util.List<org.jvnet.hk2.config.ConfigModel> getRealChildConfigModels(org.jvnet.hk2.config.ConfigModel childModel, org.jvnet.hk2.config.DomDocument domDocument)
           
static java.util.Map<java.lang.String,java.lang.String> getResourceLinks(org.jvnet.hk2.config.Dom dom, javax.ws.rs.core.UriInfo uriInfo, boolean canShowDeprecated)
           
static java.util.Map<java.lang.String,java.lang.String> getResourceLinks(java.util.List<org.jvnet.hk2.config.Dom> proxyList, javax.ws.rs.core.UriInfo uriInfo)
           
static javax.ws.rs.core.Response getResponse(int status, java.lang.String message, javax.ws.rs.core.HttpHeaders requestHeaders, javax.ws.rs.core.UriInfo uriInfo)
          Constructs and returns the appropriate response object based on the client.
static RestConfig getRestConfig(org.jvnet.hk2.component.Habitat habitat)
           
static java.lang.String getResultType(javax.ws.rs.core.HttpHeaders requestHeaders)
           
static java.lang.String getUnqualifiedTypeName(java.lang.String qualifiedTypeName)
           
static boolean isDeprecated(org.jvnet.hk2.config.ConfigModel model)
           
static boolean isOnlyATag(org.jvnet.hk2.config.ConfigModel model)
           
static void purgeEmptyEntries(java.util.Map<java.lang.String,java.lang.String> data)
           
static void resolveParentParamValue(java.util.HashMap<java.lang.String,java.lang.String> commandParams, javax.ws.rs.core.UriInfo uriInfo)
          Resolve command parameter value of $parent for the parameter in the given map.
static RestActionReporter runCommand(java.lang.String commandName, java.util.Map<java.lang.String,java.lang.String> parameters, org.jvnet.hk2.component.Habitat habitat, java.lang.String resultType)
          Executes the specified __asadmin command.
static RestActionReporter runCommand(java.lang.String commandName, ParameterMap parameters, org.jvnet.hk2.component.Habitat habitat, java.lang.String resultType)
           
static java.util.HashMap<java.lang.String,java.lang.String> translateCamelCasedNamesToXMLNames(java.util.Map<java.lang.String,java.lang.String> sourceData)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

adjustParameters

public static void adjustParameters(java.util.Map<java.lang.String,java.lang.String> data)
Adjust the input parameters. In case of POST and DELETE methods, user can provide name, id or DEFAULT parameter for primary parameter(i.e the object to create or delete). This method is used to rename primary parameter name to DEFAULT irrespective of what user provides.


defineDefaultParameters

public static void defineDefaultParameters(java.util.Map<java.lang.String,java.lang.String> data)
Adjust the input parameters. In case of POST and DELETE methods, user can provide id or DEFAULT parameter for primary parameter(i.e the object to create or delete). This method is used to rename primary parameter name to DEFAULT irrespective of what user provides.


getCommand

public static java.lang.String getCommand(RestRedirect.OpType type,
                                          org.jvnet.hk2.config.ConfigModel model)
Returns the name of the command associated with this resource,if any, for the given operation.

Parameters:
type - the given resource operation
Returns:
String the associated command name for the given operation.

runCommand

public static RestActionReporter runCommand(java.lang.String commandName,
                                            java.util.Map<java.lang.String,java.lang.String> parameters,
                                            org.jvnet.hk2.component.Habitat habitat,
                                            java.lang.String resultType)
Executes the specified __asadmin command.

Parameters:
commandName - the command to execute
parameters - the command parameters
habitat - the habitat
Returns:
ActionReport object with command execute status details.

runCommand

public static RestActionReporter runCommand(java.lang.String commandName,
                                            ParameterMap parameters,
                                            org.jvnet.hk2.component.Habitat habitat,
                                            java.lang.String resultType)

getMethodMetaData

public static MethodMetaData getMethodMetaData(java.lang.String command,
                                               org.jvnet.hk2.component.Habitat habitat,
                                               java.util.logging.Logger logger)
Constructs and returns the resource method meta-data.

Parameters:
command - the command associated with the resource method
habitat - the habitat
logger - the logger to use
Returns:
MethodMetaData the meta-data store for the resource method.

getMethodMetaData

public static MethodMetaData getMethodMetaData(java.lang.String command,
                                               java.util.HashMap<java.lang.String,java.lang.String> commandParamsToSkip,
                                               org.jvnet.hk2.component.Habitat habitat,
                                               java.util.logging.Logger logger)
Constructs and returns the resource method meta-data.

Parameters:
command - the command assocaited with the resource method
commandParamsToSkip - the command parameters for which not to include the meta-data.
habitat - the habitat
logger - the logger to use
Returns:
MethodMetaData the meta-data store for the resource method.

resolveParentParamValue

public static void resolveParentParamValue(java.util.HashMap<java.lang.String,java.lang.String> commandParams,
                                           javax.ws.rs.core.UriInfo uriInfo)
Resolve command parameter value of $parent for the parameter in the given map.

Parameters:
uriInfo - the uri context to extract parent name value.

getMethodMetaData

public static MethodMetaData getMethodMetaData(org.jvnet.hk2.config.ConfigModel configBeanModel)
Constructs and returns the resource method meta-data. This method is called to get meta-data in case of update method (POST).

Parameters:
configBeanModel - the config bean associated with the resource.
Returns:
MethodMetaData the meta-data store for the resource method.

getMethodMetaData2

public static MethodMetaData getMethodMetaData2(org.jvnet.hk2.config.Dom parent,
                                                org.jvnet.hk2.config.ConfigModel childModel,
                                                int parameterType)

copyParameterMetaDataAttribute

protected static void copyParameterMetaDataAttribute(ParameterMetaData from,
                                                     ParameterMetaData to,
                                                     java.lang.String key)

getInterfaces

protected static void getInterfaces(java.lang.Class<?> clazz,
                                    java.util.List<java.lang.Class<?>> interfaces)

commandIsPresent

public static boolean commandIsPresent(org.jvnet.hk2.component.Habitat habitat,
                                       java.lang.String commandName)

getParamMetaData

public static java.util.Collection<CommandModel.ParamModel> getParamMetaData(java.lang.String commandName,
                                                                             org.jvnet.hk2.component.Habitat habitat,
                                                                             java.util.logging.Logger logger)
Constructs and returns the parameter meta-data.

Parameters:
commandName - the command associated with the resource method
habitat - the habitat
logger - the logger to use
Returns:
Collection the meta-data for the parameter of the resource method.

getParamMetaData

public static java.util.Collection<CommandModel.ParamModel> getParamMetaData(java.lang.String commandName,
                                                                             java.util.Collection<java.lang.String> commandParamsToSkip,
                                                                             org.jvnet.hk2.component.Habitat habitat,
                                                                             java.util.logging.Logger logger)
Constructs and returns the parameter meta-data.

Parameters:
commandName - the command associated with the resource method
commandParamsToSkip - the command parameters for which not to include the meta-data.
habitat - the habitat
logger - the logger to use
Returns:
Collection the meta-data for the parameter of the resource method.

purgeEmptyEntries

public static void purgeEmptyEntries(java.util.Map<java.lang.String,java.lang.String> data)

getResponse

public static javax.ws.rs.core.Response getResponse(int status,
                                                    java.lang.String message,
                                                    javax.ws.rs.core.HttpHeaders requestHeaders,
                                                    javax.ws.rs.core.UriInfo uriInfo)
Constructs and returns the appropriate response object based on the client.

Parameters:
status - the http status code for the response
message - message for the response
requestHeaders - request headers of the request
Returns:
Response the response object to be returned to the client

getActionReportResult

public static ActionReportResult getActionReportResult(ActionReport parentActionReport,
                                                       java.lang.String message,
                                                       javax.ws.rs.core.HttpHeaders requestHeaders,
                                                       javax.ws.rs.core.UriInfo uriInfo)

getActionReportResult

public static ActionReportResult getActionReportResult(ActionReport.ExitCode status,
                                                       java.lang.String message,
                                                       javax.ws.rs.core.HttpHeaders requestHeaders,
                                                       javax.ws.rs.core.UriInfo uriInfo)

getDeleteResponse

public static javax.ws.rs.core.Response getDeleteResponse(int status,
                                                          java.lang.String message,
                                                          javax.ws.rs.core.HttpHeaders requestHeaders,
                                                          javax.ws.rs.core.UriInfo uriInfo,
                                                          org.jvnet.hk2.component.Habitat habitat)
special case for the delete operation: we need to give back the URI of the parent since the resource we are on is deleted

Parameters:
status -
message -
requestHeaders -
uriInfo -
Returns:

addQueryString

public static void addQueryString(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> qs,
                                  java.util.Map<java.lang.String,java.lang.String> data)

This method takes any query string parameters and adds them to the specified map. This is used, for example, with the delete operation when cascading deletes are required:

DELETE http://localhost:4848/.../foo?cascade=true

The reason we need to use query parameters versus "body" variables is the limitation that HttpURLConnection has in this regard.

Parameters:
data -

addQueryString

public static void addQueryString(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> qs,
                                  java.util.Properties data)

convertToXMLName

public static java.lang.String convertToXMLName(java.lang.String name)

translateCamelCasedNamesToXMLNames

public static java.util.HashMap<java.lang.String,java.lang.String> translateCamelCasedNamesToXMLNames(java.util.Map<java.lang.String,java.lang.String> sourceData)
Returns:
A copy of given sourceData where key of each entry from it is converted to xml name

getResultType

public static java.lang.String getResultType(javax.ws.rs.core.HttpHeaders requestHeaders)

buildMethodMetadataMap

public static java.util.Map buildMethodMetadataMap(MethodMetaData mmd)

isDeprecated

public static boolean isDeprecated(org.jvnet.hk2.config.ConfigModel model)

getResourceLinks

public static java.util.Map<java.lang.String,java.lang.String> getResourceLinks(org.jvnet.hk2.config.Dom dom,
                                                                                javax.ws.rs.core.UriInfo uriInfo,
                                                                                boolean canShowDeprecated)

getUnqualifiedTypeName

public static java.lang.String getUnqualifiedTypeName(java.lang.String qualifiedTypeName)
Parameters:
qualifiedTypeName -
Returns:
unqualified type name for given qualified type name. This is a substring of qualifiedTypeName after last "."

isOnlyATag

public static boolean isOnlyATag(org.jvnet.hk2.config.ConfigModel model)

getRealChildConfigModels

public static java.util.List<org.jvnet.hk2.config.ConfigModel> getRealChildConfigModels(org.jvnet.hk2.config.ConfigModel childModel,
                                                                                        org.jvnet.hk2.config.DomDocument domDocument)

getResourceLinks

public static java.util.Map<java.lang.String,java.lang.String> getResourceLinks(java.util.List<org.jvnet.hk2.config.Dom> proxyList,
                                                                                javax.ws.rs.core.UriInfo uriInfo)

getCommandLinks

public static java.util.List<java.util.Map<java.lang.String,java.lang.String>> getCommandLinks(java.lang.String[][] commandResourcesPaths)

addMethodMetaData

public static void addMethodMetaData(ActionReport ar,
                                     java.util.Map<java.lang.String,MethodMetaData> mmd)

getRestConfig

public static RestConfig getRestConfig(org.jvnet.hk2.component.Habitat habitat)

canShowDeprecatedItems

public static boolean canShowDeprecatedItems(org.jvnet.hk2.component.Habitat habitat)

authenticateViaAdminRealm

public static AdminAccessController.Access authenticateViaAdminRealm(org.jvnet.hk2.component.Habitat habitat,
                                                                     com.sun.grizzly.tcp.http11.GrizzlyRequest req)
                                                              throws javax.security.auth.login.LoginException,
                                                                     java.io.IOException
Authenticate the given req against admin realm.

Returns:
Access as granted by authenticator
Throws:
javax.security.auth.login.LoginException
java.io.IOException

authenticateViaAdminRealm

public static AdminAccessController.Access authenticateViaAdminRealm(org.jvnet.hk2.component.Habitat habitat,
                                                                     com.sun.grizzly.tcp.http11.GrizzlyRequest req,
                                                                     java.lang.String remoteHost)
                                                              throws java.io.IOException,
                                                                     javax.security.auth.login.LoginException
Authenticate the given req as originated from given remoteHost against admin realm.

Returns:
Access as granted by authenticator
Throws:
java.io.IOException
javax.security.auth.login.LoginException


Copyright © 2012 GlassFish Community. All Rights Reserved.