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.GlomTable;
9 import org.glom.web.client.TableNameService;
11 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
13 @SuppressWarnings("serial")
14 public class TableNamesServiceImpl extends RemoteServiceServlet implements
16 private Document document;
18 public TableNamesServiceImpl() {
20 // FIXME Need to call Glom.libglom_deinit()
21 document = new Document();
22 document.set_file_uri("file://" + Glom.GLOM_EXAMPLE_FILE_DIR + File.separator + "example_music_collection.glom");
24 @SuppressWarnings("unused")
25 boolean retval = document.load(error);
26 // FIXME handle error condition
30 public GlomTable[] getNames() {
31 StringVector names = document.get_table_names();
32 int tableSize = safeLongToInt(names.size());
33 GlomTable[] tableNames = new GlomTable[tableSize];
34 for (int i = 0; i < tableSize; i++) {
35 tableNames[i] = new GlomTable(names.get(i));
40 // FIXME I think Swig is generating long on 64-bit machines and int on 32-bit machines - need to keep this constant
41 // From http://stackoverflow.com/questions/1590831/safely-casting-long-to-int-in-java
42 public static int safeLongToInt(long l) {
43 if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
44 throw new IllegalArgumentException
45 (l + " cannot be cast to int without changing its value.");