class CreateJavaMailResource implements AdminCommand {

    public void execute(AdminCommandContext context) {

        final ActionReport report = context.getActionReport();

        HashMap attributes = new HashMap();
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.JNDI_NAME, jndiName);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_HOST, mailHost);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_USER, mailUser);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_FROM_ADDRESS, fromAddress);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO, storeProtocol);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_STORE_PROTO_CLASS, storeProtocolClass);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO, transportProtocol);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_TRANS_PROTO_CLASS, transportProtocolClass);
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.MAIL_DEBUG, debug.toString());
        attributes.put(org.glassfish.resources.admin.cli.ResourceConstants.ENABLED, enabled.toString());
        attributes.put(ServerTags.DESCRIPTION, description);

        ResourceStatus rs;

        try {
            rs = mailResMgr.create(domain.getResources(), attributes, properties, target);
        } catch(Exception e) {
            Logger.getLogger(CreateJavaMailResource.class.getName()).log(Level.SEVERE,
                    "Unable to create Mail Resource " + jndiName, e);
            String def = "Mail resource: {0} could not be created";
            report.setMessage(localStrings.getLocalString("create.mail.resource.fail",
                    def, jndiName) + " " + e.getLocalizedMessage());
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
            return;
        }
        ActionReport.ExitCode ec = ActionReport.ExitCode.SUCCESS;
        if (rs.getStatus() == ResourceStatus.FAILURE) {
            ec = ActionReport.ExitCode.FAILURE;
            if (rs.getMessage() == null) {
                 report.setMessage(localStrings.getLocalString("create.mail.resource.fail",
                    "Unable to create Mail Resource {0}.", jndiName));
                
            }
            if (rs.getException() != null)
                report.setFailureCause(rs.getException());
        }
        if(rs.getMessage() != null){
            report.setMessage(rs.getMessage());
        }
        report.setActionExitCode(ec);
    }

}