Search in sources :

Example 11 with ResourceAdapterConfig

use of org.glassfish.connectors.config.ResourceAdapterConfig in project Payara by payara.

the class DeleteResourceAdapterConfig method execute.

/**
 * Executes the command with the command parameters passed as Properties
 * where the keys are the paramter names and the values the parameter values
 *
 * @param context information
 */
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    if (raName == null) {
        report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.noRARName", "No RAR name defined for resource adapter config."));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    // ensure we already have this resource
    if (ConnectorsUtil.getResourceByName(domain.getResources(), ResourceAdapterConfig.class, raName) == null) {
        report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.notfound", "Resource-Adapter-Config for {0} does not exist.", raName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        // delete resource-adapter-config
        if (ConfigSupport.apply(new SingleConfigCode<Resources>() {

            public Object run(Resources param) throws PropertyVetoException, TransactionFailure {
                ResourceAdapterConfig resource = (ResourceAdapterConfig) ConnectorsUtil.getResourceByName(domain.getResources(), ResourceAdapterConfig.class, raName);
                if (resource != null && resource.getResourceAdapterName().equals(raName)) {
                    return param.getResources().remove(resource);
                }
                // not found
                return null;
            }
        }, domain.getResources()) == null) {
            report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.fail", "Unable to delete resource adapter config {0}", raName));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }
    } catch (TransactionFailure tfe) {
        report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.fail", "Unable to delete resource adapter config {0}", raName) + " " + tfe.getLocalizedMessage());
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(tfe);
    }
    // report.setMessage(localStrings.getLocalString("delete.resource.adapter.config.success",
    // "Resource adapter config {0} deleted", raName));
    report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
Also used : TransactionFailure(org.jvnet.hk2.config.TransactionFailure) SingleConfigCode(org.jvnet.hk2.config.SingleConfigCode) ResourceAdapterConfig(org.glassfish.connectors.config.ResourceAdapterConfig) Resources(com.sun.enterprise.config.serverbeans.Resources) ActionReport(org.glassfish.api.ActionReport)

Aggregations

ResourceAdapterConfig (org.glassfish.connectors.config.ResourceAdapterConfig)11 Resources (com.sun.enterprise.config.serverbeans.Resources)4 Property (org.jvnet.hk2.config.types.Property)4 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)2 BindableResource (com.sun.enterprise.config.serverbeans.BindableResource)2 Resource (com.sun.enterprise.config.serverbeans.Resource)2 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 ConnectorRuntime (com.sun.enterprise.connectors.ConnectorRuntime)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 ActionReport (org.glassfish.api.ActionReport)2 AdminObjectResource (org.glassfish.connectors.config.AdminObjectResource)2 ConnectorResource (org.glassfish.connectors.config.ConnectorResource)2 WorkSecurityMap (org.glassfish.connectors.config.WorkSecurityMap)2 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)2 Module (com.sun.enterprise.config.serverbeans.Module)1 SetMethodAction (com.sun.enterprise.connectors.util.SetMethodAction)1 ConnectorConfigProperty (com.sun.enterprise.deployment.ConnectorConfigProperty)1 PropertyVetoException (java.beans.PropertyVetoException)1 List (java.util.List)1