Пример #1
0
 public void setModel(NamedBean nb) {
   attributes = new Vector<KeyValueModel>(nb.getPropertyKeys().size());
   Iterator<String> ite = nb.getPropertyKeys().iterator();
   while (ite.hasNext()) {
     String key = ite.next();
     KeyValueModel kv = new KeyValueModel(key, nb.getProperty(key));
     attributes.add(kv);
   }
   wasModified = false;
 }
Пример #2
0
    public void updateModel(NamedBean nb) {
      if (!wasModified()) {
        return; // No changed made
      } // add and update keys
      for (int i = 0; i < attributes.size(); i++) {
        KeyValueModel kv = attributes.get(i);
        if ((kv.key != null)
            && // only update if key value defined, will do the remove to
            ((nb.getProperty(kv.key) == null) || (!kv.value.equals(nb.getProperty(kv.key))))) {
          nb.setProperty(kv.key, kv.value);
        }
      }
      // remove undefined keys

      Iterator<String> ite = nb.getPropertyKeys().iterator();
      while (ite.hasNext()) {
        if (!keyExist(ite.next())) // not very efficient algorithm!
        {
          ite.remove();
        }
      }
      wasModified = false;
    }