/** * Saves an object's data to an XMLControl. * * @param control the control to save to * @param obj the object to save */ public void saveObject(XMLControl control, Object obj) { ParticleModel p = (ParticleModel) obj; // save mass control.setValue("mass", p.getMass()); // $NON-NLS-1$ // save track data XML.getLoader(TTrack.class).saveObject(control, obj); // save parameters, initial values and functions Parameter[] params = p.getParamEditor().getParameters(); control.setValue("user_parameters", params); // $NON-NLS-1$ Parameter[] inits = p.getInitEditor().getParameters(); control.setValue("initial_values", inits); // $NON-NLS-1$ UserFunction[] functions = p.getFunctionEditor().getMainFunctions(); control.setValue("main_functions", functions); // $NON-NLS-1$ functions = p.getFunctionEditor().getSupportFunctions(); if (functions.length > 0) control.setValue("support_functions", functions); // $NON-NLS-1$ // save start and end frames (if custom) if (p.startFrame > 0) control.setValue("start_frame", p.startFrame); // $NON-NLS-1$ if (p.endFrame < Integer.MAX_VALUE) control.setValue("end_frame", p.endFrame); // $NON-NLS-1$ // save inspector size and position if (p.inspector != null && p.trackerPanel != null && p.trackerPanel.getTFrame() != null) { // save inspector location relative to frame TFrame frame = p.trackerPanel.getTFrame(); int x = p.inspector.getLocation().x - frame.getLocation().x; int y = p.inspector.getLocation().y - frame.getLocation().y; control.setValue("inspector_x", x); // $NON-NLS-1$ control.setValue("inspector_y", y); // $NON-NLS-1$ control.setValue("inspector_h", p.inspector.getHeight()); // $NON-NLS-1$ control.setValue("inspector_visible", p.inspector.isVisible()); // $NON-NLS-1$ } }
/** * Gets a simple class name for the specified class type. * * @param type the class * @return the simple class name */ public static String getSimpleClassName(Class type) { String name = type.getName(); // trim trailing semicolon, if any int i = name.indexOf(";"); // $NON-NLS-1$ if (i > -1) { name = name.substring(0, i); } // add brackets for arrays while (name.startsWith("[")) { // $NON-NLS-1$ name = name.substring(1); name = name + "[]"; // $NON-NLS-1$ } // eliminate leading package name, if any String ext = XML.getExtension(name); if (ext != null) { name = ext; } // substitute int for I and double for D arrays i = name.indexOf("["); // $NON-NLS-1$ if (i > -1) { String s = name.substring(0, i); if (s.equals("I")) { // $NON-NLS-1$ s = "int"; // $NON-NLS-1$ } else if (s.equals("D")) { // $NON-NLS-1$ s = "double"; // $NON-NLS-1$ } else if (s.equals("Z")) { // $NON-NLS-1$ s = "boolean"; // $NON-NLS-1$ } name = s + name.substring(i); } return name; }
@Override public ArrayList<RemoteObject> deserializeArray(String queryScope, String input) { String bodyFormat = getDeserializationBodyFormat(); if (XML.equals(bodyFormat)) { return deserializeArrayAsXml(queryScope, input); } else if (JSON.equals(bodyFormat)) { return deserializeArrayAsJson(queryScope, input); } else { return deserializeArrayAsJson(queryScope, input); } }
@Override public RemoteObject deserialize(String queryScope, String input) { String bodyFormat = getDeserializationBodyFormat(); // TODO parse role if auth object Parser parser = null; if (XML.equals(bodyFormat)) { parser = createXmlParser(queryScope, input); } else if (JSON.equals(bodyFormat)) { parser = createJsonParser(queryScope, input); } else { parser = createJsonParser(queryScope, input); } return deserialize(queryScope, parser); }
/** * Loads an object with data from an XMLControl. * * @param control the control * @param obj the object * @return the loaded object */ public Object loadObject(XMLControl control, Object obj) { // load track data XML.getLoader(TTrack.class).loadObject(control, obj); ParticleModel p = (ParticleModel) obj; p.mass = control.getDouble("mass"); // $NON-NLS-1$ p.inspectorX = control.getInt("inspector_x"); // $NON-NLS-1$ p.inspectorY = control.getInt("inspector_y"); // $NON-NLS-1$ p.inspectorH = control.getInt("inspector_h"); // $NON-NLS-1$ p.showInspector = control.getBoolean("inspector_visible"); // $NON-NLS-1$ Parameter[] params = (Parameter[]) control.getObject("user_parameters"); // $NON-NLS-1$ p.getParamEditor().setParameters(params); params = (Parameter[]) control.getObject("initial_values"); // $NON-NLS-1$ // remove trailing "0" from initial condition parameters for (int i = 0; i < params.length; i++) { Parameter param = params[i]; String name = param.getName(); int n = name.lastIndexOf("0"); // $NON-NLS-1$ if (n > -1) { // replace parameter with new one name = name.substring(0, n); Parameter newParam = new Parameter(name, param.getExpression()); newParam.setDescription(param.getDescription()); newParam.setNameEditable(false); params[i] = newParam; } } p.getInitEditor().setParameters(params); UserFunction[] functions = (UserFunction[]) control.getObject("main_functions"); // $NON-NLS-1$ p.getFunctionEditor().setMainFunctions(functions); functions = (UserFunction[]) control.getObject("support_functions"); // $NON-NLS-1$ if (functions != null) { for (int i = 0; i < functions.length; i++) { p.getFunctionEditor().addObject(functions[i], false); } } p.functionPanel.refreshFunctions(); int n = control.getInt("start_frame"); // $NON-NLS-1$ if (n != Integer.MIN_VALUE) p.startFrame = n; else { p.startFrameUndefined = true; } n = control.getInt("end_frame"); // $NON-NLS-1$ if (n != Integer.MIN_VALUE) p.endFrame = n; return obj; }
/** @deprecated */ void add(XML xml) { _add(xml.getAnnotation()); }
@Override public String serialize() { String bodyFormat = getSerializationBodyFormat(); SerializerBuilder builder = null; String recordSelector = HttpAdapter.createResponseWrangling(this).getRecordSelector(); if (XML.equals(bodyFormat)) { builder = new XmlSerializer.XmlSerializerBuilder(recordSelector); } else if (JSON.equals(bodyFormat)) { builder = new JsonSerializer.JsonSerializerBuilder(recordSelector); } else if (FORM_ENCODED.equals(bodyFormat)) { builder = new FormEncodedSerializer.FormEncodedSerializerBuilder(recordSelector); } final RouterAdapter routerAdapter = RemoteRailsConfig.getRouterAdapterByClass(this.getClass()); if (builder != null && routerAdapter != null) { builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("id"), "id"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("comments"), "comments"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("currency"), "currency"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("last_price"), "last_price"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("last_qty"), "last_qty"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("price"), "price"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("quantity"), "quantity"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("side"), "side"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("status"), "status"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("symbol"), "symbol"); builder.addFieldMapping( ((HttpAdapter) routerAdapter) .getConfigurationsAsConfiguration("POST") .getResponseRemoteFieldName("transact_time"), "transact_time"); return builder.create().serialize(this); } else { return super.serialize(); } }