dde8834791008a5f9f9ab831ee75151a950c10ba
[packages/precise/mcollective.git] / lib / mcollective / vendor / json / java / src / json / ext / ParserService.java
1 /*
2  * This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
3  *
4  * Distributed under the Ruby and GPLv2 licenses; see COPYING and GPL files
5  * for details.
6  */
7 package json.ext;
8
9 import java.io.IOException;
10 import java.lang.ref.WeakReference;
11
12 import org.jruby.Ruby;
13 import org.jruby.RubyClass;
14 import org.jruby.RubyModule;
15 import org.jruby.runtime.load.BasicLibraryService;
16
17 /**
18  * The service invoked by JRuby's {@link org.jruby.runtime.load.LoadService LoadService}.
19  * Defines the <code>JSON::Ext::Parser</code> class.
20  * @author mernen
21  */
22 public class ParserService implements BasicLibraryService {
23     public boolean basicLoad(Ruby runtime) throws IOException {
24         runtime.getLoadService().require("json/common");
25         RuntimeInfo info = RuntimeInfo.initRuntime(runtime);
26
27         info.jsonModule = new WeakReference<RubyModule>(runtime.defineModule("JSON"));
28         RubyModule jsonExtModule = info.jsonModule.get().defineModuleUnder("Ext");
29         RubyClass parserClass =
30             jsonExtModule.defineClassUnder("Parser", runtime.getObject(),
31                                            Parser.ALLOCATOR);
32         parserClass.defineAnnotatedMethods(Parser.class);
33         return true;
34     }
35 }