Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.api.admin;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import org.glassfish.api.ActionReport;
import org.glassfish.api.Param;
import org.glassfish.hk2.api.ServiceLocator;
/**
* Utility class for command framework. Currently it just provides hooks for command runner, to extend command
* functionality using aspects. It might be extended in future with more listeners for command life cycle phases, and
* additional utility methods. This class is in development and is subject to change.
*
* @author andriy.zhdanov
*
*/
public final class CommandSupport {
/**
* Get parameter value for a command.
*
* @param command
* @param name parameter name
*
* @return parameter value or null in case of any problem.
*/
public static String getParamValue(AdminCommand command, String name) {
return getParamValue(command, name, String.class);
}
/**
* Get parameter value for a command.
*
* @param command
* @param name parameter name
* @param paramType expected return type
*
* @return parameter value or null in case of any problem.
*/
public static T getParamValue(AdminCommand command, String name, Class paramType) {
AdminCommand unwrappedCommand = getUnwrappedCommand(command);
Class> commandClass = unwrappedCommand.getClass();
for (final Field field : commandClass.getDeclaredFields()) {
Param param = field.getAnnotation(Param.class);
if (param != null && name.equals(CommandModel.getParamName(param, field))) {
if (!paramType.isAssignableFrom(field.getType())) {
break; // return null
}
try {
AccessController.doPrivileged((PrivilegedAction