예제 #1
0
	public void formEntrySaved(FormDef form, FormInstance instanceData, boolean formWasCompleted) {
		System.out.println("form is complete: " + formWasCompleted);
 
		//Warning, this might be null
		final SubmissionProfile profile = form.getSubmissionProfile();
		
		if (formWasCompleted) {
			
			// We want to cache this send before we actually ask, otherwise the user could quit before it is
			// either sent _or_ saved.
			
			IStorageUtility storage = StorageManager.getStorage(FormInstance.STORAGE_KEY);
			try {
				Logger.log("formentry","writing data: " + instanceData.getName());
				storage.write(instanceData);
				final int record = instanceData.getID();

				TransportMessage message = JRDemoContext._().buildMessage(instanceData, profile);
				
				CompletedFormOptionsState completed = new CompletedFormOptionsState(message) {
	
					public void sendData(TransportMessage message) {
						
						JRDemoFormTransportState send = new JRDemoFormTransportState(message, record) {
							public void done() {
								JRDemoUtil.goToList(cameFromFormList);
							}
		
							public void sendToBackground() {
								JRDemoUtil.goToList(cameFromFormList);
							}
						};
							
						send.start();
					}
	
					public void skipSend(TransportMessage message) {
						// Message should already be cached.
						abort();
					}
				};
				completed.start();
			} catch (StorageFullException e) {
				new RuntimeException("Storage full, unable to save data.");
			}
		} else {
			abort();
		}
	}
  public static void importRMS(FormInstance dm, IStorageUtility storage, Class type, String path) {
    if (!Externalizable.class.isAssignableFrom(type) || !Restorable.class.isAssignableFrom(type)) {
      return;
    }

    boolean idMatters = Persistable.class.isAssignableFrom(type);

    String childName = ((Restorable) PrototypeFactory.getInstance(type)).getRestorableType();
    TreeElement e = dm.resolveReference(absRef(path, dm));
    Vector children = e.getChildrenWithName(childName);

    for (int i = 0; i < children.size(); i++) {
      FormInstance child = subDataModel((TreeElement) children.elementAt(i));

      Restorable inst = (Restorable) PrototypeFactory.getInstance(type);

      // restore record id first so 'importData' has access to it
      int recID = -1;
      if (idMatters) {
        recID = ((Integer) getValue(RECORD_ID_TAG, child)).intValue();
        ((Persistable) inst).setID(recID);
      }

      inst.importData(child);

      try {
        if (idMatters) {
          storage.write((Persistable) inst);
        } else {
          storage.add((Externalizable) inst);
        }
      } catch (Exception ex) {
        throw new RuntimeException(
            "Error importing RMS during restore! ["
                + type.getName()
                + ":"
                + recID
                + "]; "
                + ex.getMessage());
      }
    }
  }
  public static FormInstance exportRMS(
      IStorageUtility storage, Class type, String parentTag, IRecordFilter filter) {
    if (!Externalizable.class.isAssignableFrom(type) || !Restorable.class.isAssignableFrom(type)) {
      return null;
    }

    FormInstance dm = newDataModel(parentTag);

    IStorageIterator ri = storage.iterate();
    while (ri.hasMore()) {
      Object obj = ri.nextRecord();

      if (filter == null || filter.filter(obj)) {
        FormInstance objModel = ((Restorable) obj).exportData();
        mergeDataModel(dm, objModel, topRef(dm));
      }
    }

    return dm;
  }