Revision 1405 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dynobject/impl/DefaultDynObjectManager.java

View differences:

DefaultDynObjectManager.java
41 41
import java.util.Set;
42 42

  
43 43
import org.gvsig.tools.ToolsLocator;
44
import org.gvsig.tools.dataTypes.DataTypes;
44 45
import org.gvsig.tools.dynobject.DelegatedDynObject;
45 46
import org.gvsig.tools.dynobject.DynClass;
46 47
import org.gvsig.tools.dynobject.DynClassName;
......
331 332
    private Map anonymousClasses;
332 333
    private ClassesNamespaces classes;
333 334
    private Map methodsMap;
334
    private MethodInfo[] methods;
335
    private List<MethodInfo> methods;
335 336

  
336 337
    public static DefaultDynObjectManager getManager() {
337 338
        if (manager == null) {
......
347 348

  
348 349
    static String getKey(Class theClass, DynClass dynClass, String methodName) {
349 350
        if (dynClass == null) {
350
            return theClass.getName() + ":" + methodName;
351
            if( theClass == null ) {
352
                return "__anonymous__:" + methodName;
353
            } else {
354
                return theClass.getName() + ":" + methodName;
355
            }
351 356
        } else {
352 357
            return dynClass.getName() + ":" + methodName;
353 358
        }
......
505 510
        return registerDynMethod(theClass, null, dynMethod);
506 511
    }
507 512

  
513
    public int registerDynMethod(DynMethod dynMethod) {
514
        return registerDynMethod(null, null, dynMethod);
515
    }
516

  
508 517
    int registerDynMethod(Class theClass, DynClass dynClass, DynMethod dynMethod) {
509 518
        MethodInfo info = new MethodInfo(theClass, dynClass, dynMethod, 0);
510 519
        MethodInfo oldInfo = (MethodInfo) methodsMap.get(info.getKey());
......
515 524
            return oldInfo.code;
516 525
        }
517 526
        if (methods == null) {
518
            methods = new MethodInfo[1];
519
            info.code = 0;
520
        } else {
521
            MethodInfo[] temp1 = new MethodInfo[methods.length + 1];
522
            System.arraycopy(methods, 0, temp1, 0, methods.length);
523
            info.code = temp1.length - 1;
524
            methods = temp1;
527
            methods = new ArrayList<MethodInfo>();
525 528
        }
526
        methods[info.code] = info;
529
        info.code = methods.size();
530
        methods.add(info);
527 531
        methodsMap.put(info.getKey(), info);
528 532

  
529 533
        return info.code;
......
540 544
             * Asi evitamos codigo de comprobacion para los casos que valla bien
541 545
             * que deberian ser la mayoria.
542 546
             */
543
            return methods[code].dynMethod.invoke(self, context);
547
            return methods.get(code).dynMethod.invoke((DynObject)self, new Object[] {context});
544 548
        } catch (RuntimeException e) {
545 549
            getDynMethod(self, code);
546 550
            throw e;
......
574 578
    }
575 579

  
576 580
    public DynMethod getDynMethod(int code) throws DynMethodException {
577
        if (code >= methods.length) {
581
        if (code >= methods.size()) {
578 582
            throw new DynMethodNotSupportedException(code, "{null}");
579 583
        }
580
        MethodInfo info = methods[code];
584
        MethodInfo info = methods.get(code);
581 585
        info.check((Class) null, code);
582 586
        return info.dynMethod;
583 587
    }
584

  
588
    
589
    @Override
590
    public DynMethod getDynMethod(String methodName) throws DynMethodException {
591
        String key = DefaultDynObjectManager.getKey(null, null, methodName);
592
        MethodInfo info = (MethodInfo) methodsMap.get(key);
593
        if (info == null) {
594
            throw new IllegalDynMethodException(methodName);
595
        }
596
        return info.dynMethod;
597
    }
598
    
585 599
    public DynMethod getDynMethod(Object obj, int code)
586 600
        throws DynMethodException {
587 601
        return getDynMethod(obj.getClass(), code);
......
589 603

  
590 604
    public DynMethod getDynMethod(Class theClass, int code)
591 605
        throws DynMethodException {
592
        if (code >= methods.length) {
606
        if (code >= methods.size()) {
593 607
            throw new DynMethodNotSupportedException(code, theClass.getName());
594 608
        }
595
        MethodInfo info = methods[code];
609
        MethodInfo info = methods.get(code);
596 610
        info.check(theClass, code);
597 611
        return info.dynMethod;
598 612
    }
599 613

  
600 614
    public DynMethod getDynMethod(DynClass dynClass, int code)
601 615
        throws DynMethodException {
602
        if (code >= methods.length) {
616
        if (code >= methods.size()) {
603 617
            throw new DynMethodNotSupportedException(code, dynClass.getName());
604 618
        }
605
        MethodInfo info = methods[code];
619
        MethodInfo info = methods.get(code);
606 620
        info.check(dynClass, code);
607 621
        return info.dynMethod;
608 622
    }
......
766 780
            }
767 781
        }        
768 782
    }
783

  
784
    @Override
785
    public DynField createDynField(String name) {
786
        return new DefaultDynField(name, DataTypes.STRING);
787
    }
788
    
789
    
769 790
}

Also available in: Unified diff