package it.sk.alfresco.clojure;

import java.io.BufferedReader;
import java.io.StringReader;

import clojure.lang.Compiler;

/**
 * Created by IntelliJ IDEA.
 * User: sku
 * Date: Apr 7, 2010
 * Time: 12:20:19 AM
 * To change this template use File | Settings | File Templates.
 */
public class RunSwankServer {
    public void init() throws Exception {
        Runnable cljRunner = new Runnable() {
            public void run() {
                Thread thisThread = Thread.currentThread();
                ClassLoader savedCL = thisThread.getContextClassLoader();

                ClassLoader newCL = this.getClass().getClassLoader();

                thisThread.setContextClassLoader(newCL);

                try {
                    clojure.lang.Compiler.load(
                            new java.io.StringReader(
                                    "(require 'clojure.main)\n" +
                                            "(require 'swank.swank)\n" +
                                            "(clojure.main/with-bindings\n" +
                                            "    (swank.swank/start-server \"nul\" :encoding \"utf-8\" :port 4005))"
                            ));
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                thisThread.setContextClassLoader(savedCL);
            }
        };

        Thread cljThread = new Thread(cljRunner);
        cljThread.start();

    }
}

@@ -302,17 +302,17 @@
 nkServer
- 
+%0A
 %7B%0A    pu
@@ -344,16 +344,20 @@
 xception
+%0A   
  %7B%0A     
@@ -394,16 +394,24 @@
 nnable()
+%0A       
  %7B%0A     
@@ -434,16 +434,28 @@
 id run()
+%0A           
  %7B%0A     
@@ -732,16 +732,32 @@
      try
+%0A               
  %7B%0A     
@@ -1236,16 +1236,32 @@
        %7D
+%0A               
  catch (
@@ -1272,16 +1272,32 @@
 ption e)
+%0A               
  %7B%0A     

Reformat to normal code style