Esempio n. 1
0
  /** Upon initialization, send across emberized forms of the (relevant) model definitions */
  public void sendModels(ErrorHandler eh) {
    for (Observer o : observers) {
      Model m = o.getModel();
      for (String docName : m.documents()) {
        for (ObjectDefinition od : m.objects(docName)) {
          try {
            JSONObject model = new JSONObject();
            model.put("modelName", StringUtil.capitalize(od.name));
            JSONObject hash = new JSONObject();
            model.put("model", hash);
            for (FieldDefinition x : od.fields()) {
              hash.put(x.name, attrOf(x.type, x));
            }
            send(model);
          } catch (JSONException ex) {
            logger.error("Error creating models", ex);
          }
        }
        /*
        for (LeaderboardDefinition ld : m.leaderboards(docName)) {
        	for (Grouping g : ld.groupings()) {
        		try {
        			String vn = ld.getViewName(g);
        			ObjectDefinition od = m.getModel(eh, vn);
        			// First define the entry
        			String lbname = StringUtil.capitalize(ld.name) + g.asGroupName();
        			String lbentry = lbname + "Entry";
        			{
        				JSONObject model = new JSONObject();
        				model.put("modelName", lbentry);
        				JSONObject hash = new JSONObject();
        				model.put("model", hash);
        				for (FieldDefinition x : od.fields()) {
        					hash.put(x.name, attrOf(x.type));
        				}
        				send(model);
        			}

        			// Then define the board
        			{
        				JSONObject model = new JSONObject();
        				model.put("modelName", lbname);
        				JSONObject hash = new JSONObject();
        				model.put("model", hash);
        				hash.put("entries", new JSONObject(CollectionUtils.map("rel", "hasMany", "name", lbentry)));
        				send(model);
        			}

        		} catch (JSONException ex) {
        			logger.error("Error creating models", ex);
        		}
        	}
        }
        */
      }
    }
  }