class CreateProfiler implements AdminCommand, AdminCommandSecurity.Preauthorization {

    public void execute(AdminCommandContext context) {
        final ActionReport report = context.getActionReport();

        if (javaConfig.getProfiler() != null) {
            System.out.println("profiler exists. Please delete it first");
            report.setMessage(
                localStrings.getLocalString("create.profiler.alreadyExists",
                "profiler exists. Please delete it first"));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            return;
        }

        try {
            ConfigSupport.apply(new SingleConfigCode<JavaConfig>() {

                public Object run(JavaConfig param) throws PropertyVetoException, TransactionFailure {
                    Profiler newProfiler = param.createChild(Profiler.class);
                    newProfiler.setName(name);
                    newProfiler.setClasspath(classpath);
                    newProfiler.setEnabled(enabled.toString());
                    newProfiler.setNativeLibraryPath(nativeLibraryPath);
                    if (properties != null) {
                        for ( Map.Entry e : properties.entrySet()) {
                            Property prop = newProfiler.createChild(Property.class);
                            prop.setName((String)e.getKey());
                            prop.setValue((String)e.getValue());
                            newProfiler.getProperty().add(prop);
                        }
                    }
                    param.setProfiler(newProfiler);                    
                    return newProfiler;
                }
            }, javaConfig);

        } catch(TransactionFailure e) {
            report.setMessage(localStrings.getLocalString("create.profiler.fail", "{0} create failed ", name));
            report.setActionExitCode(ActionReport.ExitCode.FAILURE);
            report.setFailureCause(e);
        }
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    }

}