protected FtpServer getConfiguration()

in core/src/main/java/org/apache/ftpserver/main/CommandLine.java [110:156]


    protected FtpServer getConfiguration(String[] args) throws Exception {

        FtpServer server = null;
        if (args.length == 0) {
            System.out.println("Using default configuration");
            server = new FtpServerFactory().createServer();
        } else if ((args.length == 1) && args[0].equals("-default")) {
            // supported for backwards compatibility, but not documented
            System.out
                    .println("The -default switch is deprecated, please use --default instead");
            System.out.println("Using default configuration");
            server = new FtpServerFactory().createServer();
        } else if ((args.length == 1) && args[0].equals("--default")) {
            System.out.println("Using default configuration");
            server = new FtpServerFactory().createServer();
        } else if ((args.length == 1) && args[0].equals("--help")) {
            usage();
        } else if ((args.length == 1) && args[0].equals("-?")) {
            usage();
        } else if (args.length == 1) {
            System.out.println("Using XML configuration file " + args[0]
                    + "...");
            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
                    args[0]);

            if (ctx.containsBean("server")) {
                server = (FtpServer) ctx.getBean("server");
            } else {
                String[] beanNames = ctx.getBeanNamesForType(FtpServer.class);
                if (beanNames.length == 1) {
                    server = (FtpServer) ctx.getBean(beanNames[0]);
                } else if (beanNames.length > 1) {
                    System.out
                            .println("Using the first server defined in the configuration, named "
                                    + beanNames[0]);
                    server = (FtpServer) ctx.getBean(beanNames[0]);
                } else {
                    System.err
                            .println("XML configuration does not contain a server configuration");
                }
            }
        } else {
            usage();
        }

        return server;
    }