001package org.nuxeo.webengine.gwt.codeserver; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import org.nuxeo.common.xmap.annotation.XNode; 007import org.nuxeo.common.xmap.annotation.XNodeList; 008import org.nuxeo.common.xmap.annotation.XObject; 009 010@XObject("codeserver") 011public class CodeServerConfig { 012 013 @XNode("@module") 014 String module; 015 016 @XNode("classpath") 017 CodeServerClasspath classpath; 018 019 @XNodeList(value = "option", type = ArrayList.class, componentType = CodeServerOption.class) 020 List<CodeServerOption> options = new ArrayList<>(); 021 022 CodeServerLauncher launcher; 023 024 private CodeServerLoader loader; 025 026 String[] toArgs() { 027 List<String> args = new ArrayList<>(); 028 for (CodeServerOption each : options) { 029 each.toArgs(args); 030 } 031 args.add(module); 032 return args.toArray(new String[args.size()]); 033 } 034 035 void startup() throws Exception { 036 loader = new CodeServerLoader(classpath.entries); 037 launcher = loader.load(); 038 launcher.startup(toArgs()); 039 } 040 041 void shutdown() throws Exception { 042 try { 043 if (launcher != null) { 044 launcher.shutdown(); 045 } 046 } finally { 047 launcher = null; 048 try { 049 if (loader != null) { 050 loader.close(); 051 } 052 } finally { 053 loader = null; 054 } 055 } 056 } 057}