Revision 45916

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/main/java/org/gvsig/fmap/dal/feature/impl/DefaultEditableFeature.java
355 355
        this.copyFrom(values, null);    
356 356
    }
357 357

  
358
    private boolean notCopyAttribute(FeatureAttributeDescriptor attr,Predicate<FeatureAttributeDescriptor> filter) {
359
        // helper function to use in copyFrom
360
        if (attr==null  ) {
361
            return true;
362
        }
363
        if (attr.isAutomatic()  || attr.isComputed() ) {
364
            return true;
365
        }
366
        if( this.isInserted() &&  attr.isReadOnly()) {
367
            return true;
368
        }
369
        if( filter!=null && !filter.test(attr) ) {
370
            return true;
371
        }
372
        return false;
373
    }
374
    
358 375
    @Override
359 376
    public void copyFrom(JsonObject values, Predicate<FeatureAttributeDescriptor> filter) {
360 377
      // iterate over the attributes and copy one by one
378
      if( values == null ) {
379
          throw new IllegalArgumentException("'values' argument can't be null");
380
      }
361 381
      boolean geometryCopied = false;
362 382
        for (FeatureAttributeDescriptor attr : this.getType()) {
363
            if (attr==null  ) {
383
            if( notCopyAttribute(attr, filter) ) {
364 384
                continue;
365 385
            }
366
            if( filter!=null && !filter.test(attr) ) {
367
                continue;
368
            }
369
            if (attr.isAutomatic()  || attr.isComputed() ) {
370
                continue;
371
            }
372
            if( this.isInserted() &&  attr.isReadOnly()) {
373
                continue;
374
            }
375 386
            String attrname = attr.getName();
376 387
            if( !values.containsKey(attrname) ) {
377 388
                continue;
......
498 509
    @Override
499 510
    public void copyFrom(Feature source, Predicate<FeatureAttributeDescriptor> filter) {
500 511
      // iterate over the attributes and copy one by one
512
        if( source == null ) {
513
            throw new IllegalArgumentException("'source' argument can't be null");
514
        }
501 515
        FeatureType sourceType = source.getType();
502 516
        for (FeatureAttributeDescriptor attr : this.getType()) {
503
            if (attr==null  ) {
517
            if( notCopyAttribute(attr, filter) ) {
504 518
                continue;
505 519
            }
506
            if( filter!=null && !filter.test(attr) ) {
507
                continue;
508
            }
509
            if (attr.isAutomatic()  || attr.isComputed() ) {
510
                continue;
511
            }
512
            if( this.isInserted() &&  attr.isReadOnly()) {
513
                continue;
514
            }
515 520
            String attrname = attr.getName();
516 521
            if( sourceType.getAttributeDescriptor(attrname)==null ) {
517 522
              continue;

Also available in: Unified diff