1 package org.glom.web.server;
5 import org.glom.libglom.Document;
6 import org.glom.libglom.Glom;
7 import org.glom.libglom.StringVector;
8 import org.glom.web.client.GlomDocument;
9 import org.glom.web.client.GlomTable;
10 import org.glom.web.client.LibGlomService;
12 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
14 @SuppressWarnings("serial")
15 public class LibGlomServiceImpl extends RemoteServiceServlet implements
17 private Document document;
19 public LibGlomServiceImpl() {
21 // FIXME Need to call Glom.libglom_deinit()
22 document = new Document();
23 document.set_file_uri("file://" + Glom.GLOM_EXAMPLE_FILE_DIR + File.separator + "example_music_collection.glom");
25 @SuppressWarnings("unused")
26 boolean retval = document.load(error);
27 // FIXME handle error condition
30 // FIXME I think Swig is generating long on 64-bit machines and int on 32-bit machines - need to keep this constant
31 // From http://stackoverflow.com/questions/1590831/safely-casting-long-to-int-in-java
32 public static int safeLongToInt(long l) {
33 if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
34 throw new IllegalArgumentException
35 (l + " cannot be cast to int without changing its value.");
41 public GlomDocument getGlomDocument() {
42 GlomDocument glomDocument = new GlomDocument();
45 glomDocument.setTitle(document.get_database_title());
47 // set array of GlomTables and the default table index
48 StringVector tableNames = document.get_table_names();
49 GlomTable[] tables = new GlomTable[safeLongToInt(tableNames.size())];
50 for (int i = 0; i < tableNames.size(); i++) {
51 String tableName = tableNames.get(i);
52 GlomTable glomTable = new GlomTable();
53 glomTable.setName(tableName);
54 glomTable.setTitle(document.get_table_title(tableName));
55 tables[i] = glomTable;
56 if (tableName.equals(document.get_default_table())) {
57 glomDocument.setDefaultTable(i);
60 glomDocument.setTableNames(tables);